I'm creating a site definition which provisions a subsite based to a webtemplate(wsp) file. This webtemplate file is packed in a feature containing a module.When the feature is activated the wsp file is added to the solution gallery. Another feature, a provisioning handler then creates a subsites based on this template.

My Problem

  1. Just adding to the solution gallery does not activate the solution. Unless the added solution is activated it cannot to used as a template. How can I activate the solution through code?
  2. Alternatively we can add the solution to SPFarm.Solutions and then perform deploysolution. Is it a good idea to proceed this way?
  3. Is there any better approach to this requirement?

Any help would be greatly appreaciated.

1 Answer 1


I would deploy wsp and activate it and handle only activation of desired features on specified web/site collection.

Activation of features can be done by website template where you can specify features to be activated.

I'm not saying this is the best approach but we use it on many projects. If there is any better solution I'd be glad to know something new and improve our deployment process.

  • When i use: SPUserSolutionCollection solutionsCollection = currentSite.Solutions; foreach (SPUserSolution solution in currentSite.Solutions) {string name = solution.Name; if (solution.Name.ToLower() == "mysolution.wsp") {mysolutionID = solution.SolutionId;}} I see currentSite.Solutions.count = 0. I tried both SPSite.solution and SPWeb.solution and end up with the same issue. What do you think I'm missing here? Feb 1, 2013 at 6:51
  • I'm not sure but isn't this only user uploaded solutions? msdn.microsoft.com/en-us/library/… I never tried activating specific solutions, I'd rather go the way activating features. If you have to activate different solutions for different site coll., split them rather into more web apps
    – luccio
    Feb 1, 2013 at 8:40
  • If currentSite.Solutions.Count == 0 it may be because your sandbox-solution (WSP) is not provisioned at the root level of your site collection, but at the sub-site level.
    – Evariste
    Feb 1, 2016 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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