Download wsp solution file from SharePoint Farm

By Namwar Rizvi - Last updated: Sunday, October 10, 2010 - Save & Share - Leave a Comment

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);
		}
	}
}
Share
Posted in Administration, C#, Code, How To, Management, Object Model, Solutions • Tags: , , , , Top Of Page

Write a comment