If you have been in a situation where things are in a big hairy mess, you probably would follow the process of elimination to ensure you are not chasing the wrong items down the rabbit hole.

Now consider you are working with SharePoint and you are in a tight spot as mentioned above. You probably want to ensure that WSS/MOSS has been configured properly and that the problem is not with the webpart you are working on, for example.

Here’s a quick and easy way of writing a “hello world” webpart that doesn’t involve features and layouts and WSPs and stsadm commands and etc.

1. Open up Visual Studio 2008 and create a new class library project (name it something unique, for example, DingDongBellWebPart) and add the following code in Class1.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web.UI.WebControls.WebParts;

namespace DingDongBellWebPart

{

public class Class1 : WebPart

{

protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)

{

writer.Write(“DingDongBell test”);

base.Render(writer);

}

}

}

}

2. Check the “Sign the assembly” checkbox in Project properties “Signing” tab as shown below

Project properties

(Click on image above for better resolution)

3. Under “Choose a strong name key file” dropdownlist, select “New”.

4. Uncheck “Protect my key file with a password” as shown below

Create Strong Name Key

5. Give it a name and click OK.

6. Build the project.

7. Drag the project’s dll from the bin folder and drop it in C:\Windows\assembly folder. This registers the DLL in the GAC.

8. Replace the values for the attributes where necessary in the line below and add this line in the <SafeControls> section in the web.config file of the website you are trying to deploy this webpart to. (You can even try the SharePoint’s central admin’s web.config file. should work.)

<SafeControl Assembly=”DingDongBellWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1af588c27b5f26e0″ Namespace=”DingDongBellWebPart” TypeName=”*” Safe=”True” />

**NOTE**: Don’t forget to replace the PublicKeyToken above. There are multiple ways to fetch the PublicKeyToken of your DLL. Here’s one way. Go to C:\Windows\assembly and right click on your assembly and click properties as shown below.

Webpart properties

9. Visit the following URL – http://insert_your_website_url_here/_layouts/NewDwp.aspx [Of course replace "insert_your_website_url_here" with your value]

10. It should show up in that list as shown below. (I know….it says GirishWebpart.Class1 in the screenshot below instead of DingDongBellWebpart.Class1. May be it is because I figured GirishWebpart was a much better name than the ridiculous-sounding DingDongBellWebpart.)

Webpart properties

(Click on image above for better resolution)

11. If it doesn’t work, reset IIS. And try again. Should work.

12. Enjoy.

Leave a Reply