in SharePoint 2010

SharePoint 2010: Sandboxed Solutions

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:

The following capabilities and elements are not available in sandboxed solutions:

  • Custom Action groups

  • HideCustomAction element

  • Content Type Binding

  • Web Application-scoped Features

  • Farm-scoped Features

Sandbox Services

Sandbox solutions are available as a farm service that you can start/stop:

image

There are three services required for Sandboxed solutions to run:

image

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=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” +

          -servicename “SPUserCodeV4”

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

image

Clicking on Specify quota templates will allow administrators to create/edit quota templates and specify the maximum usage based on points.

image

In the Configure quotas and locks, administrators can assign the quota to a site collection.

image

Building a simple Sandboxed Web Part Solution

Create a new Empty SharePoint Project

image

In the SharePoint Configuration Wizard, choose to Deploy as sandboxed solution

image

Visual Studio will create the necessary project files

image

Add a new Web Part item to the project

image 

Here is my code inside the web part class

[ToolboxItemAttribute(false)]
public class MySBWebPart : WebPart
{
ListBox lstProjects = new ListBox();

public MySBWebPart()
{
}

protected override void CreateChildControls()
{
SPLinqDataContext context = new SPLinqDataContext("http://demo2010a");

var projects = context.Projects;
foreach (var project in context.Projects)
{
lstProjects.Items.Add(project.Title);
}

context.Dispose();

Controls.Add(lstProjects);
}
}

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

image

The solution will now be available in the Solutions Gallery in your site (Site Actions->Site Settings and under Galleries)

image

You can find all the user solutions there

image

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

image

Write a Comment

Comment

Time limit is exhausted. Please reload the CAPTCHA.