Sunday, July 5, 2009

Deploy a WebPart in Sharepoint Site

There are many ways to deploy a Webpart in SharePoint sites.
The easiest method is, when you want to deploy a "Sharepoint Webpart" in a given SharePoint site.

Lets Disscus this easy method:

To Deploy a Sharepoint webpart ,folow the steps below:

1. Create a Sharepoint Webpart Project. The Code for which would look like:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace Web_part1
{
[Guid("ab8354bd-824b-4dfd-a996-4c0324a1bb95")]
public class Web_Part1 : System.Web.UI.WebControls.WebParts.WebPart
{
public Web_Part1()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("Hi, This a test for WebPart deployment!");
}
} }


2. Next we will give the Assembly, a Strong name by assigning it a Public key value. To do that Right Click on the project title(in Solution Explorer Window) and go to Properties.
Go to Signing tab, and select a key in dropdown Or you can create a new public key(using sn.exe tool) and then browse it in "signing key file name" field.

3. Now go to Debug tab and select "Start browser with Url" option and write the url of the Sharepoint site, where you want to deploy the Webpart.




4. And now you are all set, Just right click on the project in Solution Explorer again and click deploy.

5. Open the sharepoint site and add a new WebPart page(Site Settings->WebPart pages). ADD a your Webpart into the site and you would see the message "Hi, This a test for WebPart deployment!"

Note: This is helpfull if you want to deploy a web-part to local server.

No comments:

Post a Comment