In this article we will discuss about Client Object Model SharePoint 2010. Also you can check out my previous posts on:
Also you can check SharePoint 2010 object model classes article.
In MOSS 2007, We have only SharePoint object model that are only available on the server. If you have to use this object model, then it must run on a SharePoint server.
provides Web services which are difficult to use and always returns XML documents and XML data needs to be parsed manually.
These are simple APIs to add, retrieve, update and manage data in SharePoint. There are some tasks you can not do using client object model like creating a web application.
These classes are very easy to use and prefix sp is removed in the naming of client object model classes. For example in Server object model if the class is SPList now in client object model the class name is List.
Behind the scene client object model interact with some wcf services to communicate with SharePoint.
To work with client object model you need to refer 2 dlls which can be found in the following locations:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI
The 2 dlls are:
Here is an example to create a list of type Announcement list by using SharePoint 2010 client object model.
using (ClientContext context = new ClientContext("http://bsahoo3:8787/sites/Training"))
//Create a new list
ListCreationInformation listCreationInformation = new ListCreationInformation();
listCreationInformation.Title = "My Announcements List";
listCreationInformation.Description += "Here is my list created by client object midel";
listCreationInformation.TemplateType = (int)ListTemplateType.Announcements;
listCreationInformation.QuickLaunchOption = Microsoft.SharePoint.Client.QuickLaunchOptions.On;
List list = context.Web.Lists.Add(listCreationInformation);