Using the SharePoint 2010 Managed Client Object Model


The SharePoint 2010 Client Object Model is a very cool feature of SharePoint 2010 Foundation Server that enables developers to write applications that access SharePoint data from a .NET application running on a client computer, from a Silverlight application, and from JavaScript running client-side in a SharePoint web part.  The client object model enables this without requiring the developer to write or install code on the SharePoint server.  The client object model makes it possible to build new categories of applications that integrate with Microsoft SharePoint Foundation 2010, including writing .NET applications, rich interactive web parts, and Silverlight applications.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOC

I’ve written an MSDN article, Using the SharePoint 2010 Managed Client Object Model, that provides the basics on using the Client Object Model.  Many thanks to Michael Cheng of the client object model team for technically reviewing the article, and providing me with many suggestions that improved it.

The article Using the SharePoint 2010 Client Object Model with the Open XML SDK 2.0 provides additional information around uploading and downloading files from a document library, as well as examples that modify Open XML documents using the Open XML SDK.

Comments (22)

  1. Ashwin Bhagwat says:

    Very good, detailed and neat article..

    Thanks Ashwin, I’m glad you like it.

    -Eric

  2. Cole says:

    Hi Eric,

    Very nice article.

    I’m running into a problem though with your very simple first example code.  I’m getting an (500) Internal Server Error when the call to ExecuteQuery runs.  I’ve looked through the server side logs, to no avail.  I’ve tried “googling” for any hint I could find, also to no avail.

    I’ve checked and double checked the DB permissions, and they seem correct.  Note for my testing purposes, I installed SP in “standalone” mode (using local admin acct to install everything).

    (500) is a pretty vague error.  Do you have hints on where I might start to ferret out the problem?  I’ve been at this the better part of the day and I’m out of ideas.  I admit I’m a complete SP newbie.

    Thanks,

    Cole

    Hi Cole, I don’t have any idea about this. One thing to check – make sure that you are using the right client-side DLLs for the specific build of SP.

    -Eric

  3. Vishal says:

    Hi Eric,

    Very nice article. Every byte has been explained in detail. Keep it up.

    Thanks! -Eric

  4. MS guy says:

    Hey Eric, Thanks for detailed article.

    Is there anyway to change the custom properties of a webpart from Silverlight using client object model??

    Thanks

    Hi MS guy, I checked with Steve Fox (one of the experts in this area), and he said, “Not out of the box. You could potentially write this across using InitParams.”

    -Eric

  5. Nikhil says:

    Cool 1 🙂 keep up the gud work . .

    Thanks, I will! -Eric

  6. Vamsi says:

    Eric

    Its a avery good article. you article is one stop shop for Client Object Model

    Hi Vamsi, glad you like it. I’m very enthused about the client object model. I have more to write about it when I get time!

    -Eric

  7. AD says:

    Eric

    Really nice article with most of the crucial info required to startup with client object model.

    However, do u know how to check whether a particular field title exists in a list or not.

    Thanks

    AD

  8. Vamsi says:

    Eric,

    i have following queries, can you please reply.

    1. How to check for null value of a variable which stores either a list ,library, field etc when we just assign its value from the ClientContext.Web

    2. How to check whether a list/library contains a particular field or not

    -Vamsi

  9. ankurmadaan says:

    Hello Eric,I have a Question,

    I am developing assembly free solutions using client object model and Ecma script,i have created a leave application using sharepoint designer which talks with the lists and server data using ecma script with client object model and Jquery,In that i have created a workflow using sharepoint designer,i.e is leave approvell workflow,there is a list "LeaveApplications".whenever a new item created or updated in this list a workflow get initiated which have some procedures to work through.i am saving this site as a template and later uploading the same solution to create another site using this template,the issue is my workflow is giving an error ,it gets initiated but not works,Can i make somehow my workflow to workflow..In an assemblly free way.???

    Please reply : ankur@zevenseas.com

  10. EricWhite says:

    Hi Ankur,

    I checked with the dev team, here’s what they said:

    —-

    Looks like his workflow is not working after packaging. I think he might be using an Approval workflow and an Approval workflow when run on packaged site threw errors in older builds. This should work in the newer builds.

    1) The workarounds for him might be republishing the workflow  (or)

    2) Deleting the xsn forms and republishing the workflows

    -Eric

  11. Ankur says:

    Thanks,

    i have allready tried with republishing it let me check one more time by deleting xsn forms.

    Regards,

    Ankur…

  12. Ankur says:

    Vamsi,

    I have an answer for you…

    I am using sharepoint designer for my ecma script code,in the early phrase of my development i also used to get such creepy errors "this field doesnt exist in the list",

    So what i do these days :

    Actually in sharepoint we have two names associted for a field,one which we display and other which is used for retrieving values from it i.e static name.

    like if i use "End Date" as field name, but its static name will be "End_x200_Date"something.

    So thats why we usually get error,even if we have field there in list,

    So while debugging sometime i check with fieldvalues();

    to get the field names.

    Or we can get the field static name by checking the source of the list page and also by looking into the "url" when click on that field in the list.

    I dont know what is the need for using two different names like this,and why not they have solved this field name spacing problem in sharepoint2010.

    regards,

    Ankur Madaan

  13. Praveen says:

    Excellent post. I also have written some articles on SharePoint 2010. Check it here.

    http://praveenbattula.blogspot.com/search/label/SharePoint%202010

  14. Sanjay says:

    Hi Eric,

    i am trying to connect to a SharePoint over HTTPS(SSL). I am getting an error when I call ExecuteQuery().

    I am using the RemoteCertificateValidationCallback to authorize the certificate.

    Please help.

  15. Sanjay says:

    Sorry, I didnt mention the error.

    "The remote server returned an error: (500) Internal Server Error".

    Thaks,

    Sanjay

  16. Tom.b says:

    thank you for the post – most helpful.

    Question: there seems to be a limit on the size of the queued transactions before a clientcontext.executequery() needs to be called.

    example: if you modify your code which adds 20 test rows (for the pagging sample) to say 1000 rows – the app will exception with a 400 bad request.

    I can reproduce this with my own program as well – i.e. try to insert 50 or so rather large list items. Unless I call executequery every few rows I always get a 400 error.

    this is very frustrating as it’s impossible to know how much data one needs to upload to a list and hence makes the ‘batching’ a guess work.

    have you come across this? the best I’ve found is something with the msg size for a web request but have not found anything indicating where this can be changed in clientcontext. As is, I’m left with a very slow insert program which does an executequery at every row.

    much appreciated

  17. country says:

    There no code sample for all the classes such list, site, web, listitem and so on .. plz update the code sample. all the comments are useless which is here right below….

  18. sturner333 says:

    Why was there no VB code listed in the atrticle? Is it not supported?

    Thanks

  19. Tushar Agarwal says:

    Hi Eric,

    I was using SharePoint 2010 client object model to upload some XML data to SharePoint list from a different network. SharePoint WFE is hosted on Rackspace and has 4 GB RAM.

    I am using following code to delete about 192 rows in SharePoint list:

    foreach (ListItem listItem in listItems.ToList())

               listItem.DeleteObject();

    SharePoint is keeping all 192 rows to delete in memory and then when I use once when I use Execute in next line, it deletes all rows together. It is timing out sometime.

    When I delete one row at a time, it is working but taking about 3 minutes to delete all 192 rows which is not acceptable.

    Any idea why my delete oparation is timing out?

    Thanks,

    Tushar

  20. Raj says:

    Hi…

    Will this sharepoint client object model using javascript (ECMA Script) works when a normal read only user visits the site?

    currently i am not able to use it for a normal reader user on the site.

    please help me.

    thanks

    raj

  21. Sarav says:

    Thanks for the blog. Can I access Sharepoint Online 2010 / Office 365 using the Managed client object model? If not, can you point me on to how to do so?

  22. SergioMuque says:

    hi, i have installed sharepoint server 2010, and i wonna know how can install it in client side.

    please help