How to Activate a Sandbox Solution using CSOM in SharePoint 2013 /Office 365?

In my Previous article , We had talked about uploading a sandbox solution using CSOM and in this article, I will talk about activating the feature which is a part of the sandbox solution. Basically, this will automatically activate the features and hence there is no need to navigate to site settings and manage site features section.

Here is the below code which activate the sandbox solution once it is uploaded.

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

namespace ActivateEmailWSP
{
class Program
{
static void Main(string[] args)
{

using (ClientContext context = new ClientContext(“yourname@yourdomain.onmicrosoft.com”))
{
SecureString passWord = new SecureString();

foreach (char c in “yourpassword”.ToCharArray()) passWord.AppendChar(c);

context.Credentials = new SharePointOnlineCredentials(“yourname@yourdomain.onmicrosoft.com”, passWord);

DesignPackageInfo info = new DesignPackageInfo()
{
PackageGuid = Guid.Empty,
MajorVersion = 1,
MinorVersion = 1,
PackageName = “Email WSP”
};
Console.WriteLine(“Installing EMail Workflow package “);

//Solution Uploaded in Solution Gallery

var solutionGallery = context.Web.Lists.GetByTitle(“Solution Gallery”);

string filerelativeurl = solutionGallery.RootFolder.ServerRelativeUrl + “/Email WSP.wsp”;

DesignPackage.Install(context, context.Site, info, filerelativeurl);
context.ExecuteQuery();

Console.WriteLine(“Applying EMAIL Workflow Package”);
DesignPackage.Apply(context, context.Site, info);
context.ExecuteQuery();
}

}
}

}
}

Hope the above code helps!! Happy SharePointing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *