Introduction
This article explains how to extract the WPSs from a SharePoint Central Admin using server-side C# coding.
Prerequisites
Ensure you have SharePoint Server.
Use the following procedure:
- Create a console application.
- Open Visual Studio as an Administrator.
- Click on "File" -> "New" -> "Project...".
- Select Console Application and enter the name as “ExtractWSP” and click on Ok.
- Go to Solution Explorer and right-click on References and add the following references.
- Microsoft.SharePoint.dll (this will be available in 14 hive folder/ISAPI).
- Add the following using references.
- using Microsoft.SharePoint;
- using Microsoft.SharePoint.Administration;
- Now copy and paste the code in the Main program.
- static void Main(string[] args)
- {
-
- Console.WriteLine("Processing");
- try
- {
- SPSolutionCollection allSolutions = SPFarm.Local.Solutions;
- foreach (SPSolution mySolution in allSolutions)
- {
- SPPersistedFile myWSP = mySolution.SolutionFile;
-
- myWSP.SaveAs("C:\\SiteAnalysis\\" + mySolution.Name);
-
- }
- Console.WriteLine("Completed");
- }
- catch (Exception ex)
- {
-
- Console.WriteLine("Error: " + ex.Message + ex.StackTrace);
- Console.ReadLine();
- }
-
- Console.ReadLine();
-
-
- }
- Create a folder called “SiteAnalysis” in the C drive.
- To make the solution work in the SharePoint 2010 environment, the following properties need to be set.
Under Application tab Target FrameWork should be “.Net FrameWork 3.5”.
Under Build tab Platform Target should be set to “Any CPU”.
Testing
- Now to run the application click on the "Play" button.
- The WPS’s that are available in the Central Admin will be saved under the following folder “C:\SiteAnalysis\”.
Summary
Thus in this article you saw how to extract the WSPs from the central admin using server-side code.