The SharePoint 2010 – Client Object Model is one of the most interesting new enhancements in SharePoint Foundation 2010 and SharePoint Server 2010. It includes 3 APIs (managed .NET, Silverlight and ECMAScript/JavaScript) allowing you to interact with SharePoint 2010 from a client which hasn’t to be run on a SharePoint server. I had some time to play around with it using resources which were available until the end of 2009.

I’m trying to become a SharePoint 2010 developer using the resources which are available. I will write down my impressions in different articles…

Resources

First of all here are the resources I used:

Videos

The first link includes 6 videos and the second link includes 3 videos with Andrew Connell.

Note: I think the first link provides videos based on SharePoint 2010 alpha or beta 1 and not the public beta… so there might be differences.

MSDN

Blog posts

Steve Peschka has written a really good series:

Using the SharePoint 2010 - Client Object Model

It’s mentioned in Steve Peschka’s series that you need to take care about the amount of data which is sent over the wire. To clarify things I tried it by myself and here are the results:

  1. The first method I have used receives 22k and includes some bad coding.
  2. The second method is optimized using a lambda expression and receives about 2k.
  3. The last method is more optimized and receives only 710 bytes.

Payloads using bad and good client object model code. 

Method 1

This method includes some unnecessary code since you don’t need to load the ‘web’, the ‘lists’ and the ‘tasklist’. You only need to use the last ctx.load() statement.

ClientContext ctx = new ClientContext(siteUrl);
Site site = ctx.Site;
Web web = site.RootWeb;
ctx.Load(web);

ListCollection lists = web.Lists;
ctx.Load(lists);

List taskList = lists.GetByTitle("Tasks");
ctx.Load(taskList);

CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>
Task1</Value></Eq></Where></Query><RowLimit>3</RowLimit></View>"
; ListItemCollection listItems = taskList.GetItems(query); ctx.Load(listItems, items => items.IncludeWithDefaultProperties(item =>
item.DisplayName)); ctx.ExecuteQuery();

Because of unnecessary code the payload (22k) is high compared to the other methods.

Method 2

Removing unnecessary code results in a lower payload (about 2k)

ClientContext ctx = new ClientContext(siteUrl);

List taskList = ctx.Web.Lists.GetByTitle("Tasks");

CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>
Task1</Value></Eq></Where></Query><RowLimit>3</RowLimit></View>"
; ListItemCollection listItems = taskList.GetItems(query); ctx.Load(listItems, items => items.IncludeWithDefaultProperties(item =>
item.DisplayName)); ctx.ExecuteQuery();

The lambda expression used in the ctx.load() statement loads all fields of a list items. If you know which columns you need you can use the third method.

Method 3

The difference is the lambda expression where you can select the properties you want to receive before you execute the query.

ClientContext ctx = new ClientContext(siteUrl);

List taskList = ctx.Web.Lists.GetByTitle("Tasks");

CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>
Task1</Value></Eq></Where></Query><RowLimit>3</RowLimit></View>"
; ListItemCollection listItems = taskList.GetItems(query); ctx.Load(listItems, items => items.Include(item => item["StartDate"], item =>
item["DueDate"], item => item.DisplayName)); ctx.ExecuteQuery();

The payload is 710 bytes. 

Summary

The SharePoint 2010 – Client Object Model is definitely a really cool feature since it allows you to access data from SharePoint with an application that doesn’t need to run on the server. And compared to the SharePoint 2007 beta phase there is enough documentation available to get started.

Comments

1/18/2010 4:31:16 PM #

Great collection of links mate!

I have also been bookmarking as I go, people might want to check out these too:

http://www.diigo.com/user/jthake/clientom

Jeremy Thake Australia Reply

1/18/2010 4:51:46 PM #

Pingback from topsy.com

Twitter Trackbacks for
        
        SharePoint 2010 - Client Object Model … becoming a SP2010 developer - Part 1
        [andreasglaser.net]
        on Topsy.com

topsy.com Reply

1/18/2010 8:16:28 PM #

@Jeremy: What a great collection of links!! :)

thx Andreas

Andreas Switzerland Reply

3/10/2010 6:37:17 PM #

Good.
I also have written some articles on SharePoint 2010 Client Object model. Check it here.
praveenbattula.blogspot.com/.../SharePoint%202010

Praveen India Reply

4/4/2010 9:57:22 PM #

All about Client Object Model in SharePoint 2010 here.

praveenbattula.blogspot.com/search/label/Client%20Object%20Model


All about SharePoint 2010:
praveenbattula.blogspot.com/.../SharePoint%202010

Praveen India Reply

7/19/2010 12:44:52 PM #

Pingback from microsoftechies.wordpress.com

SharePoint 2010 – Complete details about Client Object Model  « Dot Net Solutions

microsoftechies.wordpress.com Reply

Add comment





  Country flag
 

biuquote
Loading