Creating Web Parts by A J Noon
This blog is not intended to be an exhaustive tutorial there is much more detail in my document on the subject Creating Web Parts by A J Noon . Below are the steps I’ve followed to get my web parts working:
Installing the templates
This will install a Visual Studio template project for creating web part using either C# or VB.NET.
- Install the web part templates for VS.NET
- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/sharepoint_webparttemplates.asp
- This will add a new web part template to Visual Studio allowing you to create a blank web part with many of the commonly used functions already defined.
Creating a web part
- Create your web part
- Start VS.NET and choose to create a new Web Part Library Project
- When you create the project it adds a RenderWebPart method, similar to the RenderWebControl method for a web control, which is used for outputting the UI.
Putting a simple line like ‘output.Write("Hello");’ will be sufficient to test that the web part works.
<SafeControls>
Deploying a web part
</SafeControls>
- Add the web part to your page!
Debugging a web part
- To debug
- In the Configuration Properties -> Debugging section of your project properties dialogue
- Set Enable ASP and ASP.NET debugging to true
- In the Configuration Properties -> Build section of your project properties dialogue
- Set the output path to your servers inetpubwwwrootin directory
- Now you can attach to the w3wp.exe (.NET) process to debug your web part (Debug -> Processes -> w3wp.exe -> CLR)
Remote Debugging a web part
- Install remote debugging services on the remote server
- Share the directory hosting the sharepoint application usually c:inetpubwwwrootin. and the directory that holds sharepoint.dll, typically this is c
rogram FilesCommon FilesMicrosoft SharedWeb server extensions60ISAPI
- Open the web part project on your local machine
- Make sure your compilation path is set to the remote machines share you created earlier
- Now debug as normal but when you go to attach to the w3wp.exe process make sure to navigate to the remote machine!
Error messages
By default the error reporting in Sharepoint is switched off and you’ll just get a generic error when something fails, look familiar?
- Edit the web.config file found in your SPS virtual folder usually c:inetpubwwwroot
- Find the <safeMode> tag and change it to:
<SafeMode MaxControls="50" CallStack="true" />
- Also make sure the <customErrors> tag is disabled:
<customErrors mode="Off" />
You will now get a proper stack trace and summary of the error ala ASP.NET when an error occurs.
And what you will get is a load of information about the process being run tagged onto the end of each page, like: