Tuesday, 24 November 2009

Debugging SmartPart User Controls

Ok, so you are faced with this situation

1. You are using SmartPart because its easier for your .NET developers to write UserControls, rather than WebParts (thank god for SharePoint 2010 where developing webparts will be easier at last).

2. Using SharePoint functions such as using SPContext and local debugging (i.e. using a normal web application for testing rather than SharePoint) present a headache, since the context is not available when you are debugging locally.

3. You need the best of both worlds, i.e. easy and quick debugging, but using SmartPart and user controls.

Here's the way to do it:

1. Create post build events which copy your User Control dll to the SharePoint folder, and your user controls to the UserControls folder

e.g. copy c:\develpment\xxx.dll c:\inetpub\wwwroot\80\wss\...

2. On the Web Application project properties, rather than using the Visual Studio web server for debugging, use the IIS webserver and specify the web application where your user controls are getting deployed.

3. Press F5 and voila, your dlls, and User Controls files are copied to SharePoint, and SharePoint is loaded and attached to the debugger.

This will now allow you to step into your User Control's code whilst having all SharePoint functions still available! :)