How to delete a Sandbox solution from Solution Gallery using CSOM in Office 365?
In this blog, I will talk about removing the sandbox solution uploaded in Solution Gallery through CSOM Code. Suppose if you have a need to delete the sandbox solution if it already exists and add the updated WSP solution. Here is the code to achieve it.
// find the solution in the gallery and delete it
var solutionGallery = SiteContext.Web.Lists.GetByTitle(“Solution Gallery”);
var files = solutionGallery.RootFolder.Files;
//Load the entire solution Gallery.
SiteContext.Load(files, fs => fs.Where(f => f.Name == “MYWSP.wsp”));
SiteContext.ExecuteQuery();
var file = files.FirstOrDefault();
if (file != null)
{
file.DeleteObject();
SiteContext.ExecuteQuery();
}
Hope that helps! Happy SharePointing folks!!