In SharePoint Online 2013, within code I can upload a site template (WSP) file to the solution gallery, at this point I'd like to activate the solution but I can't find any way of doing this in code.

Any ideas?

  • There is a powershell script for this on codeplex somewhere. At present I cannot find it, but how it works is basically mimicking the users actions to perform the task. You say Client Side do you mean JSOM or CSOM? – Hugh Wood Feb 18 '14 at 11:58
  • CSOM is preferable, I've marked Vardhaman's reply as the answer but I'd be interested in the code on codeplex, though I would suspect it would be Server side code which can definitely do it. – Terry Hagan Feb 18 '14 at 16:54

Yes you can activate the solution using code in SharePoint 2013. The process is primarily for applying design packages, but they work with regular solutions too. Please have a look at the following code:

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Publishing;
using System;
using System.Security;

using (ClientContext context = new ClientContext("https://yoursite.sharepoint.com/sites/test/"))
    SecureString passWord = new SecureString();

    foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);

    context.Credentials = new SharePointOnlineCredentials("yourname@yoursite.onmicrosoft.com", passWord);

    DesignPackageInfo info = new DesignPackageInfo()
        PackageGuid = Guid.Empty,
        MajorVersion = 1,
        MinorVersion = 1,
        PackageName = "MyWSPPackage"
    Console.WriteLine("Installing design package ");

    //Relative Path of Solution Uploaded in Solution Gallery
    string fileRelativePath = "/sites/test/_catalogs/solutions/MyWSPPackage.wsp";

    DesignPackage.Install(context, context.Site, info, fileRelativePath);

    Console.WriteLine("Applying Design Package!");
    DesignPackage.Apply(context, context.Site, info);

I have modified the code which was available on the following blog: http://blog.symprogress.com/2013/07/apply-designpackage-using-client-object-model/

  • 1
    Really dude, if you are going to steal other peoples work and post it, make sure you a) check if it is actually doing what is required and b) give credit. – Hugh Wood Feb 18 '14 at 12:06
  • 1
    How do you mean steal other peoples work? This is the code I have used previously to successfully activate sandbox solutions. Can you please substantiate your claim? Also, although this process is primarily for applying design packages, they work with regular solutions too. – Vardhaman Deshpande Feb 18 '14 at 12:44
  • 1
    Will edit my answer to add more details. – Vardhaman Deshpande Feb 18 '14 at 12:47
  • Where does the "DesignPackage" class come from? Is that built into the CSOM? – Derek Gusoff Feb 18 '14 at 12:49
  • It is part of the Microsoft.SharePoint.Client.Publishing dll. Will update the answer with that thanks. – Vardhaman Deshpande Feb 18 '14 at 12:51

Found a few commercial solutions out there with this kind of capability, including CloudPower/CloudPrep. There's also a set of PSM1 PowerShell modules on CodePlex that includes this ability.

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.