none
How to check SharePoint Client Object Model is enabled or not? RRS feed

  • Question

  • Hi,
    Is it possible to check programmatically (VS 2010 & C#) whether Microsoft SharePoint Client Object Model is supported in a server or not?

    When I connected to a 2007 SharePoint site using Microsoft SharePoint Client Object Model, I got "The remote server returned an error: (500) Internal Server Error.". As the exception is generic, I'm skeptical to trap this exception and consider that the server doesn't support  SharePoint Client Object Model. Is there a way to find this?

    I know that there is no client object model (COM) in SP 2007, but how do I ensure this programmatically is my question. The logic i'm building for my tool is "If SP COM is not supported then use SP webservices" 


    RSP

    • Edited by rsp82 Monday, January 2, 2012 9:48 AM
    Monday, January 2, 2012 8:02 AM

Answers

  • Hi rsp82,

     

    As I understand, you want to get the SharePoint version on the server at first, and then you will use client OM (SharePoint 2010) or Web Service (SharePoint 2007) in your logic.

    You can use the “HttpWebRequest” and “HttpWebResponse” class to get the server version. Here is some sample code:

    HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://<servername>/default.aspx");

     request.Credentials=new NetworkCredential("<username>","<password>","<domain>");

     HttpWebResponse response =(HttpWebResponse)request.GetResponse();

     request.Accept = "text/plain";

     Console.WriteLine("Server Version:{0}",response.GetResponseHeader("MicrosoftSharePointTeamServices"));

     

    When it’s a SharePoint 2010 site, you will get the result likes this: MicrosoftSharePointTeamServices: 14.0.0.6106

    And in SharePoint 2007 site, the result likes this: MicrosoftSharePointTeamServices:12.0.0.4518

    After get the server version, you can do other logic in your code.

     

    At the same time, you can use SharePoint Web service for 2007 and 2010.


    Wayne Fan

    TechNet Community Support

    Thursday, January 5, 2012 7:03 AM

All replies

  • At first I was thinking you could check if you could make a request to  http://[server]/_vti_bin/client.svc since client.svc is the entry point for the client object model. This resulted in the msg "Endpoint not found", I'm not sure what's up with that. Then I thought: 2007 doesn't support REST, but 2010 does. So you can instead leverage the REST endpoint, ie http://[server]/_vti_bin/listdata.svc . If it's there, you know that the client OM is supported as well.  My blog post http://sharepointdragons.com/2011/12/09/building-a-jquery-autocomplete-textbox-using-the-sharepoint-rest-api/ discusses how to use jQuery to call the REST API, that should get you started.


    Kind regards,
    Margriet Bruggeman

    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com


    • Edited by Margriet Bruggeman Monday, January 2, 2012 10:03 AM
    • Marked as answer by rsp82 Monday, January 2, 2012 10:08 AM
    • Unmarked as answer by rsp82 Monday, January 2, 2012 10:12 AM
    Monday, January 2, 2012 9:59 AM
  • Hi rsp82,

     

    As I understand, you want to get the SharePoint version on the server at first, and then you will use client OM (SharePoint 2010) or Web Service (SharePoint 2007) in your logic.

    You can use the “HttpWebRequest” and “HttpWebResponse” class to get the server version. Here is some sample code:

    HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://<servername>/default.aspx");

     request.Credentials=new NetworkCredential("<username>","<password>","<domain>");

     HttpWebResponse response =(HttpWebResponse)request.GetResponse();

     request.Accept = "text/plain";

     Console.WriteLine("Server Version:{0}",response.GetResponseHeader("MicrosoftSharePointTeamServices"));

     

    When it’s a SharePoint 2010 site, you will get the result likes this: MicrosoftSharePointTeamServices: 14.0.0.6106

    And in SharePoint 2007 site, the result likes this: MicrosoftSharePointTeamServices:12.0.0.4518

    After get the server version, you can do other logic in your code.

     

    At the same time, you can use SharePoint Web service for 2007 and 2010.


    Wayne Fan

    TechNet Community Support

    Thursday, January 5, 2012 7:03 AM