Creating Visual Web Parts for Sharepoint 2010 using Visual Studio 2010 – Part 1
Visual Studio 2010 development tools for Sharepoint 2010 provide an easy way to develop custom solutions for Sharepoint with minimum effort. Developing for Sharepoint 2010 is now as easy as developing ASP.NET web applications.
Development tools like project template specific for Sharepoint 2010, Workflow templates and Visual Web Parts templates greatly enhances developer productivity and saves lot of development time.
In this article, we’re going to see how to use visual web part template and develop a custom solution in Sharepoint 2010 with minimum code and effort.
We’re going to create a web part that will display a list of available SharePoint lists in the current web site. Once the web part is developed and deployed into the site, it can be used in any Sharepoint page.
Follow these steps to create a new project in Visual Studio 2010.
Open Visual Studio 2010, Select File, New, Project from the menu.
Select Visual C#, SharePoint, 2010 from Installed Templates
Select Visual Web Part and type name and location for your project files
Once project is successfully created, Visual Studio 2010 will provide you with a default web part called VisualWebPart1. We can add as many web parts as we want for our project.
Customizing Visual Web Part
Design the web part to your requirements, in this case we’ve added a Label and Listbox control from the Toolbox.
public partial class vwpListUserControl : UserControl
protected void Page_Load(object sender, EventArgs e)
SPWeb web = SPContext.Current.Web;
foreach (SPList list in web.Lists)
The code is simple, we’re creating a SPWeb object for the current sharepoint site and looping through the lists and populating the list control with sharepoint list name and id.
That’s it, run the project (press F5) from Visual Studio 2010 to deploy and test the solution.
The Run command will deploy the custom solution to the sharepoint site we’ve mentioned while creating the project.
Insert the web part into sharepoint page by doing the following:
Select Edit to edit the sharepoint page.
Goto Insert tab and click Web Part
Select Custom from Categories and web part name Web Parts section
Click Add to insert our new web part into the page.
In just about minutes we’ve developed a fully functional web part that is ready to be used across sharepoint sites. Though we’ve started simple, in the coming articles we’ll explore more options about how to work with sharepoint object like lists, document libraries, workflows etc. and create custom solutions with minimum effort.