Sharepoint2010, Uncategorized

Visual Web Parts for SharePoint in the Sandbox | Visual Webpart | Abdul Aziz Farooqi …


One of the great feature in SharePoint I found recently when I need to create a solution protected with minimal rights on SharePoint farm, I found that with the new release addition in the SharePoint we can developed visual web part as sandbox with little tricky solution, and off course with single vs 2010 power tool, being a SharePoint developer it makes my life easy.

In this lab I am creating a single solution which can add one visual web part and then deployed as the sandbox solution to my specific site collection.

First we need to add the Visual Studio 2010 SharePoint Power Tool, which help us to make it possible, Visual web part as sanbox.

powertool

powertool

Now at this point, we add the power tool in the visual studio, Tricks begin after this.
(1) Create a simple Empty SharePoint Project, On the name textbox wirte the name and on the location write the below text
C:\%Office365TrainingKit%\2.1\Source\Before

C:\%Office365TrainingKit%\2.1\Source\Before

(2) Add the Viusal web part, you can observe easily due to power you can have option of Visual Web part as (Sandbox)

visual web part sandbox...

visual web part sandbox...

Once you add the visual web part (sandbox) to solution, the next window you will have the visual studio wizard which can ask you the sitecollection address or make it as farm base solution as we had on other simple webpart

visual web part sandbox sp2010

visual web part sandbox sp2010

If we look in the solution explorer, no addition file is added to make it solution as sandbox ,

visual webpart 2010 sandbox

visual webpart 2010 sandbox

now start lab with this visual web part…
add the following mark up to the webpart pgae.

Select List:

 

.cs file add the following code.

using System.Linq;
using System.Collections.Generic;

protected void Page_Load(object sender, EventArgs e)
{
// if (!Page.IsPostBack)
// {
SPWeb web = SPContext.Current.Web;

var ListNames = from SPList list in web.Lists
where list.BaseTemplate !=
SPListTemplateType.DocumentLibrary
select list.Title;

ddlLists.DataSource = ListNames;
ddlLists.DataBind();
}
//}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
SPList SourceList =
SPContext.Current.Web.Lists.TryGetList(ddlLists.SelectedValue);

SPQuery qry = new SPQuery();
qry.ViewFieldsOnly = true;
qry.ViewFields = “<FieldRef Name=’Title’ /><FieldRef Name=’Author’ />”;
qry.RowLimit = 20;

gridListItems.DataSource = SourceList.GetItems(qry).GetDataTable();
gridListItems.EmptyDataText =
string.Format(
“The {0} list does not contain any items!”,
SourceList.Title);

gridListItems.DataBind();
}
catch (Exception ex) { }
}

Now Deploy the solution. To test the this webpart,

visual web part 2010 sandbox

visual web part 2010 sandbox

visual webpart 2010 sandbox

visual webpart 2010 sandbox

Open Viusal studio and press CTRL + ALT + P and then attached the process with (SPUCWORKERPROCESS, AND SPUCWORKERPROCSSPROXY) .

attachproces

attachproces

visual studio 2010 viusal web part

visual studio 2010 viusal web part

This is great work done by the Mike Morton, greate mile stone has been covered in sp2010. If we look in to the webpart with detail every object in this web part has become a global at certain level which might have some reason😛.

visal web part as sandbox

visal web part as sandboxvisal web part as sandbox

….

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s