Archive | May 2008

Debugging in Sharepoint

Debugging in sharepoint is the same as any other web application like ASP.NET, the only thing that we should make sure before debugging is that the debugger is attached to the process.
Now,lets see one scenario where we need to debug the code.
To configure VS debugger one can follow these steps :

Go to VS Tools >Options menu

Make sure that you have unchecked the option and then click ‘OK’
Then,go to Debug > Attach to process menu to attach the code to the w3wp process as shown below

It can be noticed from the screenshot that there may be several instances of the process running, to know are you attached to the correct process, first attach to that process ,press Ctrl +Alt + U and check if your dll has been loaded or not(See below screenshot) .If its loaded then, you are attached to the correct process or else try attaching other instances till you could see your dll loaded properly.

CustomWebPart.dll is my dll that has been loaded, so my code has been attached to the right process.
Once,this is done on performing an operation your breakpoint should get hit ,something like this

This kind of technique can be used to debug the code that has its dll in GAC (like web parts and the custom aspx pages in the layouts folder )But, this technique cannot be used for the custom pages that uses the inline code approach ,since its dll won’t be in the GAC.

To debug the inline code , go to the web.config file of that site, set debug = true in the compilation tag and also make sure that the code that should be hit is within the Try-Catch block.Once,these settings are done you can debug the inline code using the same technique.

Customize the Web Part Properties in Sharepoint

Web Parts are the basic units of sharepoint,its pretty easy to create a custom web part.However,the challenge lies in its customization as per the requirements. I have been busy these days working on the web part customizations, one such feature that fascinates me is the customization of web part properties.

Customizing the web part properties includes 2 steps :

1.Set the web part property attributes.

2.Create Property accessors.

Now,lets see each one of them in detail

1.Set the web part property attributes – Most of the web part proerty attributes comes from the namespace “System.ComponentModel .Here are some of the attributes that we can make use of :

Category -It specifies a separate category for the custom properties to be displayed on the property pane.

WebBrowsable – Specifies if the property should be visible on the pane or not. We need to set this to “true” to make it availabe to the users.

WebDisplayName – Display name for the custom property.

WebDescription – Description for the custom property.

We can have these attributes defined something like this

[Category(“Name”),Personalizable(PersonalizationScope.Shared), WebBrowsable (true),WebDisplayName(“UserName for Output”),WebDescription(“Enter Ur name for Output”)]

2.Create property accessors – Web Part requires the appropriate get and set accessors methods.

public string DisplayName




return Name;




Name = value;



Once we are done with these steps,we should be getting our custom property in the property pane as shown below