Wednesday, January 4, 2012

Sandbox Solutions in SharePoint 2010 – Part 2


In this post we are going to see how to create and deploy sandbox solution. If you have not gone through part-1 of this series, I would recommend you reading it first and then continue reading from here on.

So let us go ahead and start the visual studio and this time we will create an empty project and select sandbox solution and not the farm solution. Select empty solution project.


Mention the URL of the site that you would like to connect to.

And click on finish. You will be presented with this screen.


If you see a property of a project, then you can see a property called Sandbox solution as true. If you wish to turn this solution to farm solution, you can always come back to property setting and set it to false. This is a handy tip. Isn’t it? J As of now we will keep it true as we are developing sandbox solution.


Now click on add new item and select web part (not visual web part – as it is not supported in sandbox solution). Give it a name SandBoxWebPart and add it to solution.

We are going to write a simple code to this. Write a code in createchildcontrols method.

protected override void CreateChildControls()
        {
            if (!Page.IsPostBack)
            {
                Label lbl = new Label
                {
                    Text = "Hello from sandbox",
                    ID = "lblSandBox",
                    ForeColor = System.Drawing.Color.Blue
                };

                Controls.Add(lbl);
            }
        }

So now we are going to package this solution, not deploy because we want to deploy it as a sandbox solution. So now you get a wsp created in your physical path of this project once you right click on project and select package.


And you can see your wsp file


Now the beauty is if you are the site collection administrator you can go ahead and deploy and activate this solution.

So let us open the site and go to site settings and go to gallery and click on solutions.


As you can see solutions quota has been assigned by farm administrators. As and when solution uses the resources it keeps increasing the bar which tells us the limit that solution has used.

Click on the solutions tab and then upload the solution. You can also down the solutions from Microsoft office.com and use it in your application.



Once you upload, you also get an option to activate at the same time. We will activate the solution. You can see it has been activated and now deployed.


Now go ahead and open the site, edit the page and add a web part. Look for the web part with the name ‘SandBoxWebPart’ in custom category.


Add that web part and this is what you get.


In next post, Read Part-3 to see how the resources count in sandbox solution. 

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 sharepointkings@gmail.com 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 sharepointkings@gmail.com