How to Upload a Sandbox Solution using CSOM in SharePoint 2013 /Office 365?
In our SharePoint cloud environment, we are uploading a sandbox solution for a email functionality. So we have developed a wsp using Visual studio 2013 environment, and manually adding to the solution gallery. We have decided to automate the manual process of uploading WSP in to solution gallery. Here is the code to achieve the functionality below.
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();
}
}
}
}
Hope the above code helps!! Happy SharePointing 🙂