Wednesday 25 April 2007

"fun" adding Webparts to SharePoint 2003

We're doing a bit of "retro" SP 2003 work for a client, and having written several webparts for 2003 I thought 1 more couldn't cause a problem. ha! how wrong could I be. We'll I created my webpart (see http://msdn2.microsoft.com/en-us/library/ms948909.aspx if you want a starting guide), and checked that everything was all named correctly. Then I tried to deploy the webpart (see http://www.codeproject.com/useritems/BasicWebPartPartII.asp) for another good guide.

When I couldn't get my web part to appear I checked the event log to find

"Failed to locate the assembly in the SafeControl assembly paths".

Trying to import the .dwp file directly from a team site (Modify Shared Page-> Add Web Parts -> Import) gave the similar error:

"A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe."

After more checking and rechecking of the .dwp file and the section of the web config I checked the virtual server. It's an older IIS 6 box, and as such was still creating sites configured for .NET 1.1 by default. Aha - I'd built my assembly with .NET 2.0. No problem, change the Virtual server over to .NET 2? Well, not quite. SharePoint is "well secure (aye)" and won't run if you do that. You need to make the further step of running stsadm to upgrade the server configuration:

stsadm -o upgrade -forceupgrade -url http://URLOftheVirtualServer

You can find full information about the problem in KB Article 894903. I really hope this saves someone the headache in these circumstances - most of the newgroup posts/replies tend generally to ignore the users actual problems, or reply with "i've fixed it" without saying what the fix was.