Code Sample : How to programmatically download all solutions (WSPs) in SharePoint

by Mark Jones | Dec 27, 2011

Once a solution has been added to SharePoint, then there's no apparent way to download it. Using the SharePoint object model we can easily download a wsp using the 'SaveAs' method. 

The C# code below illustrates how to download all of the solutions in the farm with just a few lines.

SPSolutionCollection solutionCollection = SPFarm.Local.Solutions;
 
foreach (SPSolution solution in solutionCollection)
{
    SPPersistedFile wsp = solution.SolutionFile;
 
        SaveWSP(wsp);
}
 
 
private void SaveWSP(SPPersistedFile wsp)
{
 if (wsp != null)
        {
 
 string fileName = Path.Combine(
 @"c:\temp\wspdownloads", 
                          wsp.Name);       
 
 if (System.IO.File.Exists(fileName))
            System.IO.File.Delete(fileName);
 
        wsp.SaveAs(fileName);
 
}


Have your say ...

blog comments powered by Disqus
Collaboris RSS Feed

RSS Feed

To get updated as we blog - get the feed.

Read & Sign in SharePoint