I have a solution (deployed in the Sandbox) that declaratively creates CustomActions (menu items). It works fine in SharePoint 2010 and 2013, but we don't like the look in 2013 so I'd like to exclude it from deploying or activating on 2013.

I could make two .wsp files, one for each version of SharePoint, but is there an another way to prevent the element with the CustomAction (or the feature that contains it) from deploying or activating on 2013?

  • How are you deploying the wsp file and activating the features currently? Would a power shell solution be helpful? – Ryan Erickson Mar 12 '13 at 23:12
  • It's a sandbox solution, so it's uploaded and activated using the browser. – Erik Erkelens Mar 13 '13 at 1:37

It looks like that the only way to do this is programmatically in a FeatureActivated event receiver.

SPWeb.UIVersion is not exactly the SharePoint version number, but it is available in the Sandbox and can be used.

The code looks like this:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    SPWeb web = properties.Feature.Parent as SPWeb;

    if (web.UIVersion == 15) return; // don't add in SP2013; 4 for 2010

    SPWeb web = properties.Feature.Parent as SPWeb;

    SPUserCustomAction customAction = web.UserCustomActions.Add();
    customAction.Title =
  • I suspect this won't work if the site in SP2013 is using the SP2010 look and feel (SPWeb.UIVersion will report 14 instead of 15), though in that case you would probably want it to activate since it will look as expected. – shufler Mar 15 '13 at 2:13
  • Correct, it was not exactly what I asked, but it was what I needed. BTW I couldn't find documentation on the numbers returned; a 2010 site returned 4 not 14. – Erik Erkelens Mar 15 '13 at 8:23
  • Interesting, good to know! – shufler Mar 15 '13 at 13:33

For Sandbox solution, you can create a custom Sandbox Solution Validator by inherting from SPSolutionValidator class.You add it to the SPUserCodeService SolutionValidators collection using either the API or PowerShell

Using solution validator, You can decide what to check on the solution and, if it fails validation, it is not allowed to be activated in the site collection.

Now, to check for SharePoint Version in the validator, you can use SPServer.Version while you override ValidateSolution() method

Check here for the details of a Solution Validator: http://zimmergren.net/technical/sp-2010-validate-sandboxed-solutions-using-spsolutionvalidator

  • Interesting, but unfortunately I have to use a Sandbox solution, and the SPSolutionValidator is not available in the Sandbox. – Erik Erkelens Mar 13 '13 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.