Wednesday, March 10, 2010

Custom Webpart in MOSS 2007

Webparts are Cool, Hot and Flexible. Ok,this was a joke, but webparts are really very helpful to add some customized support to your sharepoint site. I hope you have the basic understanding of what is webpart and how to add/remove a webpart from sharepoint site. Here I will discuss two ways to deploy custom sharepoint site, the first one is messy and the second one is hilarious(not so sure about the adjective!). Read the first one if you want to curse me or skip to the next one.

Prerequisite :
Install an extension for your VS, you will find it in http://www.microsoft.com/downloads/details.aspx?FamilyID=B2C0B628-5CAB-48C1-8CAE-C34C1CCBDC0A&displaylang=en or google with "visual studio extension for sharepoint 1.3" if fail to click/copy the link from here(is not that an impossible case?) This extension is known as VSEWSS.

First Method :

Step 1 : Open VS2008 and try to create a new Project. As you have installed VSEWSS you will find a new category in create project named “SharePoint”. Choose an Empty template.

Step 2 : Now in your blank project add a Web Part through Add -> New Item -> Web Part. A new web part is created in your project. Write your code here according to your need or leave it as it is if you are only learning.

Step 3 : Now right clicking on the project in Solution Explorer you will find a new option, “Package”. Click it and your web part is done :)

Now the next is to deploy it...

Step 4 : Now add "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN" this to your path variable. Why? I will not tell you.Google for the answer if you don’t know. To make it path variable run this in cmd,

>set path=%path%;"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN";.

Step 5 : Now in cmd go to Debug folder of your project. You will find a .wsp file in this folder named after your webpart. Now to add your WebPart to your Sahrepoint site run the following command.

>stsadm -o addsolution -filename FirstWebPart.wsp

Step 6 : Now open Sharepoint Central Administration. Go to Central Administration > Operations > Solution Management

If you are not damn unlucky you will find your web part here listed. Click it and Deploy it.

Step 7 : Now go to your sharepoint site. Click Site Actions and go to Site Settings > Site Features

Here you will find your web part,just activate it.

Step 8 : Now go to Site Actions>Edit Page and add you web part in the page.

Wow it’s visible in your page and you are really done with your web part :)

Step 9 : If you like to upgrade your webpart run the command in cmd in Debug folder of your project
>stsadm -o upgradesolution -name FirstWebPart.wsp -filename FirstWebPart.wsp -immediate –allowgacdeployment

Or
Just paste the dll of the solution into GAC and iireset. For this you have to assign strong name to your dll,Google for how to assign strong name to dll.

Second Method :
This is same up to Step 3 of First Method, just the deployment portion is different. So follow up to Step 3 and then

Step 4 :
Build the webpart solution and copy the dll of the web application.

Step 5 : Put the dll in the bin direstory of virtual directory of your site.

Step 6 : Right click on the webpart project and see the properties. Here put the link of the sharepoint site in Debug box and put a new key file name Signing box. Build the project.

Step 7 : Now Right click on the webpart project and click Deploy.

Step 8 : Now go to your sharepoint site. Click Site Actions and go to Site Settings > Site Features

Here you will find your web part,just activate it.

Step 9 : Now go to Site Actions>Edit Page and add you web part in the page.

Wow it’s visible in your page and you are really done with your web part :)

No comments: