Pages

Feb 4, 2011

SharePoint 2010: Introducing the Client Object Model

Today

If you want to access SharePoint Server 2007 Data today, you have two ways of doing it (based on your needs):

  1. Writing a Server Application
    • This application resides in server
  2. Writing a Client Application
    • This client application can run from any other server or a desktop

How are we building these Server and Client applications today?

Server Application

SharePoint Server Application

We interact with the Server Object Model, which are nothing but SharePoint APIs and build applications.

For example:

List announcements = new List();
SPSite site = SPContext.GetContext(HttpContext.Current).Site;
using (SPWeb curWeb = site.OpenWeb())
{
      SPList lstAnnouncements = curWeb.Lists[new Guid(LibraryName)];
 
      //rest of the code
}

Client Application

SharePoint Client Application

We use the SharePoint Web Services which then interacts with the SharePoint API. Usually, developers either build their own set of web services which exposes only certain methods/functions they want to expose to the application or consume the default out of the box SharePoint web services. This becomes difficult if you are going write rich client applications such as Silverlight, or Javascript applications and most of the time accessing SharePoint data via web services is complicated. That is why, I am not going to show you an example code!

The Future of SharePoint Client Applications

SharePoint 2010 introduces the new Client Object Model. From the sneak peak videos:

“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.”

So, how things are going to change?

Shareoint Client Application

One API to rule them all – Yep, whether its WPF or Windows Forms or Silverlight or Javascript – your code uses Client Object Model to interact with the SharePoint site to access the data. Now, there is something common that everybody can use instead of creating their own wrapper services to access SharePoint data!

Any code sample?

The only source of information available for now is the Developer Sneak Peak Video.

In the video, a Silverlight application is built using the Client Object Model.

The assemblies added to the project are:

Client Object Model

  • Microsoft.SharePoint.Client.Silverlight.dll
  • Microsoft.SharePoint.Client.Silverlight.Runtime.dll

And also there is a using statement added in the code behind:

Client Object Model

using Microsoft.SharePoint.Client;

And the code showcasing this new Client Object Model:

Client Object Model Code

You can explore the Microsoft.SharePoint.Client namespace in the SharePoint 2010 Technical Preview Documentation

Microsoft.SharePoint.Client namespace

Lets hope this Client Object Model simplifies accessing SharePoint data from client applications :)

No comments: