In this article we can explore how to get SharePoint Solutions through code. We are using Server Object Model to retrieve the solutions.
As you know there are 2 types of Solutions in SharePoint:
- Sandboxed Solutions
- Farm Solutions
Are Sandboxed & Farm Solutions retrieved differently?
Yes! They both are deployed through various methods & they are retrieved through various object models.
Note: Sandboxed Solution is represented by SPUserSolution class & Farm Solution is represented by SPFarmSolution class.
How to get Sandboxed Solutions?
Sandboxed Solutions are deployed in the Site Collection level. (Feature Activation is different where we activate both for Site Collection & Site levels)
Following is the property to get User Solutions.
site.Solutions
Following is the code to retrieve all User Solutions in a Site Collection:
using (SPSite site = new SPSite("http://localhost"))
{
foreach (SPUserSolution solution in site.Solutions)
{
Console.WriteLine(solution.Name);
Console.WriteLine(solution.Status);
}
}
How to get Farm Solutions?
Farm Solutions exist at the Farm Level. The following is the property to get Farm Solutions:
SPFarm.Local.Solutions
The following is the code to retrieve all Farm Solutions:
foreach (SPSolution solution in SPFarm.Local.Solutions)
{
Console.WriteLine(solution.Name);
Console.WriteLine(solution.SolutionId);
Console.WriteLine(solution.Status);
}
Now let us see the installion of solutions through the Server Object Model.
Install Sandboxed Solution
Installation of a solution is a 2-step process consisting of:
-
Adding Solution to Gallery
-
Activating Solution
The following is the code to add a solution to the gallery:
using (SPSite site = new SPSite("http://localhost"))
{
SPDocumentLibrary gallery
=(SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog);
SPFile file = gallery.RootFolder.Files.Add("SandboxedSolution.wsp",
File.ReadAllBytes("SandboxedSolution.wsp"));
SPUserSolution solution = site.Solutions.Add(file.Item.ID);
}
Remove Sandboxed Solution
For removing a solution & deactivating its features, the following code can be used:
using (SPSite site = new SPSite("http://localhost"))
{
SPUserSolution solution = site.Solutions.Cast<SPUserSolution>().

Join the conversation! Your thoughts help the community grow.