There are two way we can build a web part.
1. Using Sharepoint extensions for Visual studio.
2. Developing a Class library and manually deploying it in Sharepoint.
Sharepoint extensions for visual studio can be downloaded from the following location
Once you have installed the extension, from Visual Studio->File->New Project->Share Point->Web Part
This will provide a template with all setting ready for building a web part. Once you have done with the web part, you can deploy it directly from Visual Studio. For doing that open the properties dialog by right click the project from solution explorer, go to the debug tab and enter the sharepoint web application URL and save the settings. You can use the same right click context menu for deploying the web part directly to sharepoint server by clicking the deploy menu item.
Manual development and deployment steps
- From visual studio File->New Project->C#->Class Library
- Right click and Add Reference of System.Web
- Rename Class.cs to NewWebPart.cs
- Open NewWebPart.cs and add the following code
- Right click project->Properties->Signing, and sign the assembly with a key
- Now build the project
- Open visual studio command prompt and use the following command
- Open your sharepoint web application's web.config file and add the following entry
- Open Site Setting from Site Actions menu
- Click on Web Parts
- Click New
public class NewWebPart: System.Web.UI.WebControls.WebParts.WebPart
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
gacutil /i C:\bin\NewWebPart.dll
Replace C:\bin\NewWebPart.dll with the location of NewWebPart.dll in your machine
<SafeControl Assembly="NewWebPart, Version=188.8.131.52, Culture=neutral, PublicKeyToken=902d73ff104745c3" Namespace="NewWebPart" TypeName="NewWebPart" Safe="True" />
Replace 902d73ff104745c3 with the token of assembly. You can find it by opening c:\windows\assembly
Select NewWebPart.NewWebPart and Click Populate Gallery
Now you can add web part on your site by editing the page.