Extracting a WSP file from a SharePoint farm


I don’t know that this should really be something you need to do too often (because of course I know you all are checking your code in to an appropriate source control so you won’t ever loose a WSP file) but I did come across a scenario where we needed to get a WSP file back out of SharePoint. There isn’t a way to do this out of the box, but lucky for us it is seriously easy to write a few lines of code to do it.
SPSolutionCollection solutions = SPFarm.Local.Solutions;
foreach (SPSolutionsolution in solutions)
{
solution.SolutionFile.SaveAs(“{path to save}”)
}
The above code sample is pretty straight forward, it gets a list of every solution through the SPFarm.Local.Solutions object, and then parses through and saves each WSP file using the SolutionFile.SaveAs method. Obviously there probably wouldn’t be a need to save every WSP file, so you would add some checking in there to find the WSP file by its name or something to that extent, but the save method is just that one line of code.

Comments

Popular Posts