Hi
What is the Client Object Model and who are we using it ? I will give an introduction to how this is working in SharePoint 2010.
SharePoint 2010 gives us some new functionality called client object model that enables us to create SharePoint solutions that run remotely from the SharePoint server farm. For example, the client object model enables you to read and manipulate SharePoint data in Windows Forms applications, Windows Presentation Framework application, Silverlight applications, and ASP.NET Web applications.
The picture below shows the “big picture” of how Client Object Model is working.
And the more technical perspective, would look like this:
There are three implementations of Client Object Model, which are WPF or Windows Forms, Silverlight or Javascript – your code uses Client Object Model to interact with the SharePoint site to access the data.
“The Client Object Model (OM) is a new programming interface for SharePoint 2010 where code runs on a user’s client machine against a local object model and interacts with data on the SharePoint Server. Client OM methods can be called from JavaScript, .NET code or Silverlight code and makes building rich client applications for SharePoint easy.”
Very good introduction videos til Client object model, see here, and of course the official MSDN description see here (actually very good).
Then we want to implement the Client OM, here are some useful facts:
When we want to start coding with the Client OM there is a little difference between the server-side object model programming, as the class names are very similar to those used in classes so far (not a clear rule, but in general have been removed the letters “SP” from the names of classes in the client-side API). Some differences are visible in this table.
| Server Object Model | Client Object Model |
| SPContext | ClientContext |
| SPWeb | Web |
| SPList | List |
| SPListCollection | ListCollection |
| SPListItem | ListItem |
| SPField | Field |
Assemblies to use in .NET client object model.
Custom .NET applications will need to add references to two assemblies in order to use the client object model. These two assemblies are found on the SharePoint server: c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI:
- Microsoft.SharePoint.Client.dll (contains the client object model)
- Microsoft.SharePoint.Client.Runtime.dll (handles all communication between the client and SharePoint server)
And the using statement will look like this:
- using Microsoft.SharePoint.Client;
.NET Client OM Code example:
private void btnGetLists_Click(object sender, EventArgs e)
{
lbLists.Items.Clear();
using (SP.ClientContext ctx = new SP.ClientContext("http://sp2010"))
{
var web = ctx.Web;
ctx.Load(web);
ctx.Load(web.Lists);
ctx.ExecuteQuery();
foreach (SP.List list in web.Lists)
{
lbLists.Items.Add(list.Title);
}
}
}
Silverlight client object model:
The Silverlight client object model add the two assembly references found in the c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder:
- Microsoft.SharePoint.Client.Silverlight.dll (contains the client object model)
- Microsoft.SharePoint.Client.Runtime.Silverlight.dll (handles all communication between the client and SharePoint server)
ECMAScript(javascript) client object model:
The ECMAScript client object model’s ClientContext constructor takes zero parameters because it’s locked to communicating only with the site the page is loaded from. This limitation prohibits cross-site scripting, a universally recognized security exploit.When writing back to SharePoint, the page that contains the ECMAScript should contain an instance of a FormDigest control to create a digest for security validation on the page. For the ECMAScript OM, you need to know some Java library,
- CUI.js (344 kb)
- SP.js (381 kb)
- SP.Core.js (13 kb)
- SP.Ribbon.js (208 kb)
- SP. …
We can find them at this path:<Drive>:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS
Detailed description of the things to be aware of when using Client OM, see here.
Best regards
Happy SharePoint 2010 explorer, Jacob








