SharePoint 2010 Client Object Model

The Client Object Model (Client OM) API can be used in .NET based applications, Silverlight applications, and in ECMAScript (JavaScript) .

Sequence of events:

Silverlight and .NET applications need reference to Microsoft.SharePoint.Client.dll and
Microsoft.SharePoint.Client.Runtime.dll to access the API. These two dlls can be downloaded from the
server where SharePoint 2010 is installed.

1. Once the client application uses Client OM, the calls are converted into XML request and sent to the
SharePoint server.
2. On the server, the XML request is handled by a service called Client.svc where it
translates the XML request into appropriate Object Model calls (SharePoint Server Object Model) and
gets the results.
3. After getting the results, Client.svc translates them into JavaScript Object Notation
(JSON) and sends back to the Client Managed Object Model.
4. On the client side, the JSON response is translated into Client OM objects.

Sample:

function DeleteItem()
{
if(window.confirm(‘Are you sure you want to delete this item?’))
{
objContext = new SP.ClientContext.get_current();
objWeb = objContext.get_web();
objList = objWeb.get_lists().getByTitle(“Product”);
objItem = objList.getItemById(strID);
objItem.deleteObject();
objContext.executeQueryAsync(Function.createDelegate(this,
this.DeleteItemSuccess), Function.createDelegate(this, this.DeleteItemFail));
}
}
function DeleteItemSuccess(sender, args)
{
window.location = “AllItems.aspx”;
}
function DeleteItemFail(sender, args)
{
alert(‘Item is not updated.’);
}

Synchronous  Vs/ Asynchronous call:

While using SharePoint Client OM in .NET or Silverlight application, both ExecuteQuery() and
ExecuteQueryAsync() are available to developers.

ExecuteQuery() is a synchronous call, which means the
client application will wait for the server’s response before jumping onto next line of code.

ExecuteQueryAsync() is an asynchronous call, so code continues to execute; the client application
doesn’t wait for server’s response and will execute the next line of code.

Summary:

Users can write .net, silverlight or ECMAScript in an ASPX page for
SharePoint 2010 sites and can manipulate the SharePoint content without the complexity of Server
Object model, or getting involved in the complexities of web services.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.