Total Productivity Solutions, Inc. Company Logo
TPS Home
.NET
IIS
Networking
Search Engine
SharePoint
Add URL

Debugging SharePoint 2003 WebParts

This article will describe how to enable the debugging of a SharePoint 2003 webpart in Visual Studio .NET.  There are two areas that need to be changed to enable debugging of SharePoint 2003 webparts.  The first is the properites of the Visual Studio project.  To make the required changes follow these steps:
  1. Open the existing web part project that you would like to debug in Visual Studio.  If the project is not already opened you can open it by going to File->Open and then browsing to the location of the file.
  2. Open the project properties.  You can do this by right clicking the project name in the solution explorer window and select properties, or you can go to Project->Properties from the menubar.
  3. In the properties window that appears, click on Configuration properties folder. 
  4. Click on the build option.
  5. Set the Output Path to be the bin folder of the site you will debug the webpart on and where the dll of the webpart is located at.
  6. Click on the debugging option.
  7. Set the Enable ASP .NET Debugging option to True.
  8. Set the Debug Mode to URL and click off of the field.  This will enable the field for Start URL field.
  9. Enter the URL for the site you will debug the webpart on in the Start URL field.
  10. Click apply and then OK.
The other area that will need to be changed is the web.config file of the site you will debug the webpart on.  to make the required changes to the web.config file follow these steps:
  1. Open the web.config file of the site.
  2. Locate the area of the web.config file
  3. Make sure that the webpart you are going to debug is listed in the safecontrols area as safe.  An example of a safe control line is:

    <SAFECONTROL Assembly="assembly_name, Version=assembly_version, Culture=assembly_culture, PublicKeyToken=assembly_public_key_token" Namespace="assembly_namespace" TypeName="*" Safe="True" />

  4. Find the area in the web.config file
  5. Change debug value to true if it is not already set at that.
  6. Save and close the web.config file
Prior to debugging you will have to attach to the W3wp.exe.  To do this follow the following steps:
  1. Open the Processes window in Visual Studio by going to Debug->Processes from the menubar
  2. Check the Show System processes and Show Processes in all Sessions checkboxes
  3. In the Available Processes click w3wp.exe in the process list and click attach.
  4. In the "Choose the program types that you want to debug" box select "Common Language Runtime" and click OK.
  5. Finally click close.
After you have attached to the w3wp.exe process you are ready to debug.  Simply open Internet Explorer and navigate to the page where the webpart to be debugged is located.  When a break part in the webpart code is hit the control will switch to the Visual Studio debugger.
You have now debugged a webpart.
Debugging SharePoint 2003 WebPart information can also be found on Microsoft's MSDN website at:     http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_SP2003_ta/html/sharepoint_debugwebparts.asp?frame=true
Posted on Tuesday, June 07, 2005 8:01 PM
Home Contact Us Site Map