Thursday 4 September 2014

Adding and activating solution in solution gallery

Fea days back, i came across this requirement to add solution to site solution gallery. I wrote below code segment :

ClientContext context = new ClientContext("http://in-air-eyshr2:1234/sites/ETD02");

//Activate Publishing feature
//Add wsp from file system to SP solution gallary
Folder destionationFolder = context.Web.GetFolderByServerRelativeUrl("_catalogs/solutions");
FileCreationInformation fci = new FileCreationInformation();
fci.Content = System.IO.File.ReadAllBytes("D:/WSPS/LDTest.wsp");
fci.Url = "LDTest.wsp";
fci.Overwrite = true;
Microsoft.SharePoint.Client.File fileToUpload = destionationFolder.Files.Add(fci);
context.Load(fileToUpload);
context.ExecuteQuery();

//Activate solution
DesignPackageInfo info = new DesignPackageInfo()
{
  PackageGuid = Guid.Empty,
  MajorVersion = 1,
  MinorVersion = 1,
  PackageName = "LDTest"
  };
  Console.WriteLine("Installing design package ");
  //Relative Path of Solution Uploaded in Solution Gallery
  //string fileRelativePath = "D:/WSPS/testwsp.wsp";
string fileRelativePath = "/sites/ETD02/_catalogs/solutions/LDTest.wsp";
DesignPackage.Install(context, context.Site, info, fileRelativePath);
context.ExecuteQuery();
Console.WriteLine("Applying Design Package!");
DesignPackage.Apply(context, context.Site, info);
context.ExecuteQuery();

and it gave me following output:

You can give me your suggestions or post relevant questions, if any

No comments:

Post a Comment

Pages

Followers