views:

259

answers:

2

I have coded a solution that uses the 2007 API to traverse the SharePoint object model. Now I need to support SP 2003 as well. What is the best way to do this?

Is it possible / recommended to use the 2007 api to get access to a 2003 SharePoint Farm?

If I use the 2007 api, do I have to use the deprecated classes to (for instance) reference a configuration database, or do I use the 2007 classes, such as SPFarm?

Or do I use the 2007 API for SP 2007 and the 2003 API for SP 2003...? Problem with this is that both use the same namespaces and class names. So it can get messy. (Except maybe if I use aliases to reference the different namespaces?)

+2  A: 

As far I know the 2007 API and the 2003 API are incompatible. So yes? you will need to implement both.

I can suggest to have interface ISharePointAPI and two implementations SharePoint2007API and SharePoint2003API. This implementations can even be packaged to different assemblies, so you will not have reference hell :). This is will also protect you from 2010 API changes as what you will need is to implement SharePoint2010API...

Mike Chaliy
Mm, I was afraid of that. Luckily I already have an interface specified as the solution operates in a COM environment.
Ries
+1  A: 

The interfaces are (mostly) compatible in a namespace/class/member USAGE but you have to use the right version of the API for the correct version of SharePoint. You also have to consider that by WSS2/SPS2003 uses .NET1.1 by default.

My solution to this is to use MSBEE and some MSBUILD ninja moves to spit out two versions from your source code.

The first targets .NET2 and references Microsoft.SharePoint.dll v12 (WSS3/MOSS2007) and the second targets .NET1.1 and references Microsft.Sharepoint.dll v11 (WSS2/SPS2003).

Its quite a faf to setup but works very well after that. Where you do have code differences you can use conditional compilation :-

#if FX1_1
   // WSS2/SPS2003 specific code
#else
   // WSS3/MOSS2007 specific code
#endif

This article gives a little more detail. Its a big topic and I've been meaning to write a blog post with some tip.

Ryan
Thanks for the input. I think we are going to target .NET3.5 anyway (for other reasons) for both products. So 2003 and 2007 users will have to install .NET3.5 to use our solution. I think they will be able to live with that.
Ries
I also noticed that even though the 2003 classes are still available in 2007 api, some methods throw exceptions telling you it is not supported. So we are going for different implementations behind a common interface. Each implementation references each own version of the api.
Ries