Monday, January 16, 2012

Sandbox Solutions in SharePoint 2010 – Part 4

If you have not gone through Part-1 to Part-3 of this series, I would recommend you reading them first and then continue from here on.

In this post, we are going to see how Visual Studio helps us creating SandBox solutions easily.
Let us open the same example that we wrote in our earlier post. 

Let us add a code of line which is actually not permitted in sandbox solution.

protected override void CreateChildControls()
                Label lbl = new Label
                    Text = "Hello from sandbox",
                    ID = "lblSandBox",
                    ForeColor = System.Drawing.Color.Blue




We know that SPSecurity is the class which is not allowed in the sandbox solution. However when I build the project and even create a package, it allows me to do that.

No errors were given and let us see if we try to deploy this package and see what happens.

So how can we ensure that something which is not allowed in sandbox solution, we should not be able to use while program against sandbox solutions.

There is a way to do this, however we need to keep in mind that this should be done only on developer’s machine and not on production. I am showing this just to give you an idea that we have something like this available which we can use but not for the production.

We know that the Microsoft.SharePoint assembly which is there in the project refers to this global path.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll

Let us go ahead and locate one more Microsoft.SharePoint dll but at other location and add it to the project. Remove the Microsoft.SharePoint dll which is right not in the project.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode\assemblies\Microsoft.SharePoint.dll

And now try to build the project.

It does not allow us to build the project because SPSecurity is not allowed to be used inside sandbox solution. 

Do not forget to remove and get the original assembly back while deploying to production.

I hope you like this series of sandbox solutions. We will keep adding new content in SandBox solution when we come across to anything. 

Till then keep reading, keep visiting SharePoint Kings as we together explore the world of SharePoint.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to