Download wsp solution file from SharePoint Farm

Some times you need to download the solution file from SharePoint Farm. SharePoint user interface does not provide any functionality to achieve it .  Don’t worry, you can extract the solution file from SharePoint Farm by using object model. Here is a simple function to extract your target solution file from SharePoint.

/// <summary>
/// Downloads the solution file from SharePoint Farm.
/// </summary>
/// <param name="targetSolutionName">Name of the target solution.</param>
/// <param name="pathToSave">The path to save.</param>
private static void DownloadSolutionFile(string targetSolutionName, string pathToSave)
 	if (!String.IsNullOrEmpty(targetSolutionName) &amp;&amp; !String.IsNullOrEmpty(pathToSave))
		//Search for target solution
		var solution = (from s in SPFarm.Local.Solutions where s.Name == targetSolutionName select s).FirstOrDefault();

		if (solution != null)
			//target solution found, extract the solution file and save it
			SPPersistedFile solutionFile = solution.SolutionFile;
			solutionFile.SaveAs(pathToSave + solutionFile.Name);

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap