SIGN UP MEMBER LOGIN:    
ARTICLE

How to create SharePoint 2010 Visual web part using Visual Studio 2010

Posted by Vijai Anand Articles | SharePoint November 20, 2010
In this article we are going to create SharePoint 2010 Visual web part using visual studio 2010.
Reader Level:

In this article we are going to create SharePoint 2010 Visual web part using visual studio 2010.

Steps Involved:

Creating Empty SharePoint Project:
  • Open Visual Studio 2010. 
  • Go to File => New => Project. 
  • Select 2010 from the installed templates SharePoint and choose Empty SharePoint Project. 
  • Name it as HelloWorld.
  • Click Add. 
  • Enter the SharePoint server farm URL. 
  • Select 'Deploy it as a Farm Solution". 
  • Click Finish.
Creating Visual web part:
  • Right click the Solution Explorer and select Add a new item. 
  • Select Visual Web Part from the installed templates SharePoint and name it as HelloWorld.

    1.gif

  • Once you create Visual Web Part automatically all the files will be generated as shown in the below figure that is required to deploy your web part directly into the SharePoint 2010.
  • In the solution explorer you could see VisualWebPart1UserControl.ascx.
  • Open the .ascx file and add one asp label control.
  • In this web part I am just going to display a label with the text as "Hello World!!!!".
  • See the below code.

    <%
    @ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="HelloWorld.VisualWebPart1.VisualWebPart1UserControl" %>
    <asp:Label ID="lblHelloWorld" runat="server" Font-Bold="True"
        ForeColor="#0066FF" Text="Hello World!!!!"></asp:Label>

  • Build the solution. 
  • Deploy the solution.
Testing:
  • Go to the SharePoint site http://servername:2010.
  • Go to Site Actions=>Edit Page.
  • In the top ribbon Editing Tools => Insert => Web Part, click on the Web Part. 

    2.gif

  • Go to Categories => Custom, you could see VisualWebPart1 which we have developed using Visual Studio 2010.

    3.gif

  • Select VisualWebPart1 and click on Add.
  • Now you will able to see the label with the text "Hello World !!!!" as shown below.

    4.gif
Summary:

In this article my intension is to give some information about how to create a simple Visual Web part (a new template that is available in visual studio) and deploy directly into the SharePoint 2010.

erver'>
Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor