views:

535

answers:

2

I need a way to determine the version of SharePoint based on the URL provided. Also, I need to have it implemented through SharePoint web services or any other method that does not involve SharePoint's object model (because the code is not executed on the server). Could anyone help please? Thanks.

A: 

Quickly browsing the webservices I couldn't find a way to do that (even in the admin.asmx service under the central admin)

Ideas:

  1. If able to impersonate as the System Account, grab the /_layouts/settings.aspx page, theres a ProductVersionString property that you can parse the html to get to (consider jquery for faster results)

  2. If able to change the server, create version.aspx page in the 12\TEMPLATE\LAYOUTS folder (or webservice) and via reflection outputs the Microsoft.SharePoint.Utilities.SPUtilityInternal type and its ProductVersionString

F.Aquino
F. Aquino, thank you for your reply. Unfortunately, this won't work with SharePoint 2010. The main reason why I need this functionality in the first place is to be able to determine whether the user provides the link to the SP2007 or SP2010 site. Sub-site creation is handled differently in these two versions, thus I need to provide branching in my code. The branching condition should say true for SP2007 or false for SP2010.
Boris
I dont see why it wouldnt, the 12 mentioned is just an example, and the Object Model hasnt changed alot for that portion, but I ended up upvoting Josha's answer below which is waaay better.
F.Aquino
I can't use SharePoint's Object Model.
Boris
+2  A: 

To achieve this you can execute a web request to your SharePoint URL and then capture a host header.

There is a host header called MicrosoftSharePointTeamServices that will provide you with the SharePoint version.

See below:

Uri uri = new Uri("http://MYSHAREPOINTSITE");
System.Net.WebRequest request = System.Net.WebRequest.create(uri);
WebResponse response = request.GetResponse();
String SharePointVersion = response.Headers["MicrosoftSharePointTeamServices"].ToString();

Then compare your SharePointVersion with the following list:

12.0.0.6535 MOSS 20071 or WSS 3.0 SP2 + December 09 cumulative Update (KB960010 + KB960011)

12.0.0.6524 MOSS 20071 or WSS 3.0 SP2 + 15th December Update (KB977027 + KB977026)

12.0.0.6520 MOSS 20071 or WSS 3.0 SP2 + October 09 cumulative Update (KB974989 + KB974988)

12.0.0.6514 MOSS 20071 or WSS 3.0 SP2 + August 09 cumulative Update (KB973400 + KB973399)

12.0.0.6510 MOSS 20071 or WSS 3.0 SP2 + June 09 cumulative Update (KB971538 + KB971537)

12.0.0.6504 MOSS 20071 or WSS 3.0 SP2 + April 09 cumulative Update (KB968850 + KB968851)

12.0.0.6421 MOSS 20071 or WSS 3.0 SP2 (KB953338 + KB953334) [Updated 1st Aug 09: SP2 download now includes the hotfix (KB971620) that corrects the activation issue more information on the Microsoft SharePoint team blog]

12.0.0.6341 MOSS 20071 or WSS 3.0 February 09 cumulative Update (KB961755 + KB961756)

12.0.0.6335 MOSS 20071 or WSS 3.0 December 08 cumulative Update (KB960010 + KB960011)

12.0.0.6331 MOSS 20071 or WSS 3.0 October 08 cumulative Update (KB957691 + KB957693,KB958567 and KB958569)

12.0.0.6327 MOSS 20071 or WSS 3.0 August 08 cumulative update (KB956056 & KB956057)

12.0.0.6318 MOSS 20071 or WSS 3.0 Infrastructure Update (KB951695 & KB951297)

12.0.0.6303 MOSS 20071 or WSS 3.0 post-SP1 hotfix (KB948945)

12.0.0.6301 MOSS 20071 or WSS 3.0 post-SP1 hotfix (KB941274)

12.0.0.6300 MOSS 20071 or WSS 3.0 post-SP1 hotfix (KB941422)

12.0.0.6219 MOSS 20071 or WSS 3.0 SP1

12.0.0.6039 MOSS 20071 or WSS 3.0 October public update

12.0.0.6036 MOSS 20071 or WSS 3.0 August 24, 07 hotfix package

12.0.0.4518 MOSS 20071 or WSS 3.0 RTM

12.0.0.4407 MOSS 20071 or WSS 3.0 Beta 2 TR

12.0.0.4017 MOSS 20071 or WSS 3.0 Beta 2

12.0.0.3111 Office 12 (PDC image - pre-beta) - This version of Office does not have a support link in the Add/Remove programs dialog box.

Joshua
Well done! Thank you for your answer. Very compact, neat and efficient code. Spot on!
Boris