SharePoint 2010 introduces new feature called Sandboxed Solutions. These sandboxed solutions are nothing but .wsp packages which has limited access to resources and runs isolated alongside other processes. Sandboxed solutions will not be able to make updates beyond the scope of the current site. You are also limited in performing farm level and web application level changes.
But Why Sandboxed Solutions?
Today, in SharePoint Server 2007, solutions are deployed in the farm level though you can activate features per web application or site. There is no proper way you can centrally manage/administer these solutions in a shared environment per web application or site. With sandboxed solutions, administrators can now allocate quotas, monitor the usage and also prevent excessive usage of resources by the solution. But yes, you are limited in the functionality what the solution can access, but as long as the solution scope is not beyond the site level, it is always better to build sandboxed solutions.
Surprisingly, Sandboxed solutions are going to play a major role in Microsoft Online Services very soon 🙂
Building a Sandboxed Solution
Building a Sandboxed solution is as simple as building a normal SharePoint application (Web Part, User Control etc.,).
Refer the following MSDN Article to find out more about Sandboxed Solutions. From MSDN:
The following capabilities and elements are available in sandboxed solutions:
WebTemplate Feature element instead of Webtemp.xml
Web Parts derived from WebPart
The following capabilities and elements are not available in sandboxed solutions:
Custom Action groups
Content Type Binding
Web Application-scoped Features
Sandbox solutions are available as a farm service that you can start/stop:
There are three services required for Sandboxed solutions to run:
You can also use stsadm command to start/stop the user code service application:
stsadm -o provisionservice -action start -servicetype +
“Microsoft.SharePoint.Administration.SPUserCodeService, Microsoft.SharePoint, Version=18.104.22.168, Culture=neutral, PublicKeyToken=71e9bce111e9429c” +
Configuring Quotas and Resource Usage
Administrators can create and configure quotas for site collection from the Central Administration.
The settings are available under Application Management | Site Collections
Clicking on Specify quota templates will allow administrators to create/edit quota templates and specify the maximum usage based on points.
In the Configure quotas and locks, administrators can assign the quota to a site collection.
Building a simple Sandboxed Web Part Solution
Create a new Empty SharePoint Project
In the SharePoint Configuration Wizard, choose to Deploy as sandboxed solution
Visual Studio will create the necessary project files
Add a new Web Part item to the project
Here is my code inside the web part class
public class MySBWebPart : WebPart
ListBox lstProjects = new ListBox();
protected override void CreateChildControls()
SPLinqDataContext context = new SPLinqDataContext("http://demo2010a");
var projects = context.Projects;
foreach (var project in context.Projects)
Very simple code, just pulling all the projects from a Projects list. Note that I am also using Linq to SharePoint
Build and Deploy the solution
The solution will now be available in the Solutions Gallery in your site (Site Actions->Site Settings and under Galleries)
You can find all the user solutions there
You can also notice the other info like resource usage and total server resources.
Now, you can add the sandboxed web part to your site page. Below is a screenshot of the sandboxed web part