February 9, 2010

Use VS 2010 to create SharePoint WSS/MOSS 2007 Webparts

Creating webparts in Visual Studio 2008 for SharePoint 2007 can be messy and the effort required is not indicative of the ease you would expect from a product like SharePoint. There are tools to help such as VseWSS and developers at Codeplex have created several solutions such as wspbuilder.  But have you checked out recent Visual Studio 2010 beta releases yet?

If you have then you probably eyed with envy the project templates for SharePoint 2010.  Developing Webparts is now a snap.  Developing, testing and deployment is done at white-knuckle speed and debugging SharePoint in 2010 works like any other Visual Studio application.

With a little hacking you can use Visual Studio 2010 to build SharePoint 2007 webparts.  Here’s what you do.

Simple Hello World

  1. Open up Visual Studio 2010 and create a new “Visual Webpart”
  2. VisualWebPart1UserControl.ascx will open automatically. To which we  add:
<asp:Label ID="Label1" runat="server" Text="Hello World">
</asp:Label>
  1. On Lines 2,3,4,7 change the Assembly version to 12.0.0.0
  2. Build > Package

This will create a wsp file containing a webpart that will run in SharePoint 2007 only.

Most of the time changing the assembly reference within the ascx file is all you need to do.  If you inherit a class within the Microsoft.SharePoint namespace you will need to replace the default reference to Microsoft.SharePoint version 14 with the older SharePoint 2007 version 12 library.

Post a Comment