Debugging Web Parts in SharePoint 2007

July 29, 2008

You finished developing your Web Part, and you pressed Crtl+Shift+B and your Build went fine, but you get errors displayed when you test your Web Part in SharePoint 2007, so what do you do now?

1. First you right-click on your project file in the solution explorer and click on “Properties”.

2. Then under the Build section you change the Output path to the bin directory in the Virtual Directory of the web application under which you want to debug your web part (this is another way to deploy your web parts besides already mentioned ways in my previous post http://dotnet.org.za/zlatan/archive/2008/03/25/developing-basic-web-parts-in-sharepoint-2007.aspx).

3. Build your project/solution (Crtl+Shift+B)

4. Next under Debug you select Attach to Process.

5. You select w3wp.exe from the list of processes (if there is more than one, then select them all just to be on the safe side).

6. I hope you didn’t forget to put a break point in your code and now debug away.


How to use Web Part Custom Properties in SharePoint 2007 and WSS 3.0

July 29, 2008

t’s so weird how so many people ask you the same thing around the same time sometimes, anyway I’ve had some request around on how to create custom properties for Web Parts in SharePoint, more to the point, on how to get them to categorise and appear in the “Modify Web Part” panel.

It’s quite simple actually, just declare the properties and decorate them with attributes like in the following example:

[WebBrowsable(true),

Personalizable(true),

Category("RSS Aggregator Web Part"),

DisplayName("URLs of the Feed"),

WebDisplayName("URLs of the Feed"),

Description("Please enter the URLs of the feed separated by ';' character.")]

public string FeedURL

{

get

{

return rssUrl;

}

set

{

rssUrl = value;

}

}

Please note that Category attribute will basically create section for all your properties that carry that attribute value and WebDisplayName will be the name of the property appearing on the panel.