jump to navigation

Working with the new Client Object Model: From SPC09 Las Vegas October 20, 2009

Posted by willhlaw in jQuery, SharePoint, Sharepoint Designer, SPC09.
Tags: , , , ,

Live from Las Vegas at Mandalay Bay. I am at the SharePoint Conference 2009 and listening to a presentation on the new SharePoint 2010 Client Object Model. Presenter was Paul Stubbs from Microsoft.

Client Object Model

  • Simple API to Add, Retrieve, Update and Manage Date in Shareponit.
  • 1st goal – consistency
    • Between client and server API
    • As well as between the three different clients, Client side (.NET), Silverlight, and Javascript.
  • 2nd goal – efficiency
    • In use of server resources
    • In use of network resources
    • Uses a SQL model. Batch up client calls, call server, server processes query, server turns results as a result set
    • Only return data the exact data that I need. i.e. When calling a list, only retrieve data for the specific columns that are needed.
  • Code example
    • Today:
      • SPWeb site = SPContext.Current.Web;
      • String title = site.Title;
      • Site.Title = title + ” and Client OM”;
      • Site.AllowUnssafeUpdates = true;
      • Site.Update();
    • Now with Client Object Model:
      • ClientContext = clientContext = new ClientContext(http://intranet.contoso.com);
      • Web site = clientContext.Web;
      • clientContext.Loadsite);
      • clientContext.ExecuteQuery(); //synchronous call
      • site.Title += ” and Client OM”;
      • site.Update((); //second call because as a rule, can’t use a property to set the value of another property.
      • clientContext.ExecuteQuery();
    • Another example:
      • Web site;
      • ClientContext ctx;
      • Void MainPage_Loaded(object sender, RoutedEventArgs e)
      • { contexzt = new ClientContext(http://mysite);
      • Site = context.Web;
      • Context.Load(site);
      • //Call the Sharepoint Server
      • Context.ExecuteQueryAsync(succeededCB, failedCB);}
    • Javascript example:
      • _spBodyOnLoadfunctionNames.push(“Initialize”);
      • Var site;
      • Var Context;
      • Function Initialize()
      • { contexst = SP{.Clientcontext.get_current();
      • Site = Context.get_web();
      • Context.load(site, “Title”);
      • //Call the Sharepoint Server
      • Context.executeQueryAsync(Suceeded, Failed);}
  • Retrieve Data
    • Context.Load(object, params LinqExpre3ssion)
      • Fills out the objects in the context; in-place
      • ‘method syntax’ linq only
  • Context.Loadquery(iQueryable)
    • Use linq query to return custom objects
    • Not filled into the client context
    • Both ‘query syntax’ and ‘method syntax’ linq
  • Query Syntax
    • More natural Linq query that is familiar
    • Var query = from list in clientContext.Web.Lists where list.Title != null select list;
  • Method Syntax
    • More technical
    • clientContext.Load(oList, list => list.Fields.Where( field => field.hidden === false && field.Filterable == true));
    • Harder, but more powerful.
  • How does this all work? How to access data with Client OM?
    • A new service called Client.svc is a proxy to WCF service.
    • When .ExecuteQuery occurs, block of XML gets sent to server, it unwinds it, and returns JSON object to client.
    • Use fiddler to see the payload to understand how it works, but once you do, can ignore the traffic details.
  • Demo 1, change site title “Hello World”:
    • Shows an example of client.svc runtime being used in a windows application to change the title of a site.
  • Client Object Model using .NET is synchronous, but Silverlight and Javascript are asynchronous.
  • Demo 2, a WPF example:
    • Purpose is to fill a list box with a List of Lists.
    • There are some namespace collisions when building the WPF app.
    • So, you must write: Using SP = Microsoft.Sharepoint.Client again to prevent namespace conflict.
    • Object model will turn query syntax into method syntax before sending it to the server. Remember, query syntax is easier to write.
  • Demo 3, showing .NET CLR in Word
    • Drop .NET controls on the canvas onto the design surface within Visual Studio.
    • Purpose is to fill a task pane (Action Pane, uses ElementHost control because it needs to be Winforms based) on the right-hand side of customer data.
    • Also showing grabbing fields from a list.
  • Demo 4, javascript and jQuery
    • In visual studio, starting a new OMJavascriptApplication
    • <SharePoint:scriptLink> name=”sp.js”. -> Name of javascript client object model
    • <script src = js/jquery-ui-1.7.1.custom.min.js and other jquery files. Presenter mentions that trontastic is a great css to use. I have to check it out.
    • Bui8lding a dynamic jQuery Accoridion on the page by setting a div id=”accordion”
    • Has a separate MyJScode.js file
      • Inside the file, uses _spBodyOnLoadfunction to push Initialize function with familiar code that gets context, etc.
      • LoadListBox is pure jQuery code to populate listbox with a change event.
      • Var listEnumerator = lists.getenumerator();
      • While listEnumerator.moveNext()) {
      • }
      • Then listbox1.append using standard jquery.
      • BuildTable(ListName) is pure jQuery code.
    • Purpose of example is to show List of Lists inside the accordion! Really cool. This caused the audience to clap for the first time in the entire demo!
  • Javascript Client OM
    • Javascript files are in the 14 bin folder on the server.
    • There is a debug version (SP.debug.js)
    • SP.Core.js and SP.Core.debug.js
    • SP.Runtime.js (SP.Runtime.debug.js)
    • Debug versions are only slighter larger.
  • Next demo, Silverlight example
    • In visual studio, starting a new OMSilverlightApplication in Visual Studio
    • Starts with a simple grid with listbox
    • Using SP = Microsoft.Sharepoint.Client again to prevent namespace conflict.
    • Can build using standard Silverlight code to run in browser or inline, which I think means stand alone on the client machine.
    • It is easy to go from WPF code to Silverlight using this.Dispatcher.BeginInvoke and using a lambda expression.
      • i.e. this.Dispatcher.BeginInvoke ( ()=> {messageBox.Show(string.Forma(“failed – msg”); })
    • There are lot of steps to publish the Silverlightproject. Seems like several options for outputting the project. Grant it, I am not familiar with Silverlight at all.
    • (uh-oh, big clapping from next session over!) Yeah Microsoft.
    • When deploying Silverlight app to Sharepoint, a Silverlight.xap file is published to a Silverlight folder located at
    • The project does not exist on the SharePoint server, it is deployed as a sandbox solution.
    • In site settings -> solutions -> OMSilverlightApplicatinoDeploy exists for a site collection administrator to deploy.
    • Since deployment option was checked to allow Silverlight webapp to be installed on client, you can right-click the Silverlight listbox app, and can install the app on the client!
    • (This got the second clap of the session from the audience!)
  • No reason to deploy in WPF (if you are not doing full trust or 3D). To have updates, click once, security, and to have offline capability, build apps in Silverlight!    
  • #SPC09Buzzword for this session, “Super Powerful. Super Powerful”
  • Silverlight CLR Client OM
    • Located in 14 bin on server.
    • Microsoft.SharePoiht.Client.Silverlight (262KB)
    • Microsoft.SharePoint.Client.Silverlight.Runtime (138KB)
  • Q & A
    • I asked what recommended methods does Microsoft have for deloying jQuery and script libraries to Sharepoint Pages. There was no real recommendation other than including it in masterpage globablly or referencing it in a single .aspx file, but Scott was the second time I heard to talk with Mike Amerland.


1. @webworldtech - October 21, 2009

Dude, you are a blogging MACHINE! I thought I was writing a lot between sessions, but dang!

willhlaw - October 21, 2009

I don’t know. You’re doing an awesome job too. Especially with your up-close photos and videos. I wish I was adept at that stuff yet. I’m still new on the blogging block. It looks like you may do work in DC, we should catch up if so.

@webworldtech - October 21, 2009

Definitely we should catch up – I live in Arlington, am in DC all the time.

2. Sunjay - October 21, 2009

awesome man. I have been following you closely , looks like you are the only one talking about Infopath. One question if that can be addresed to MS, is will they have the requiste training material, in terms of books and stuff like that. Previsouly there were hardly any stuff on InfoPath 2007, we can forget 2003. Nothing came out of MS Press.

Please keep blogging on about InfoPath and SPD, they rock and always did. (they are GnR, Ozzy, Van halen, Journey , all rolled into one). Kool

willhlaw - October 21, 2009

Thanks. I’m glad you are finding my posts helpful. Tonight is the “Ask the Experts” so I will try to ask for more materials on these subjects. I am certainly going to try to find out Microsofts strategy or at least best practices when it comes to coding javascript in Sharepoint and calling jQuery, jPoint, and other javascript libraries.

willhlaw - October 23, 2009


I was able to talk to two Microsoft members of the InfoPath and Forms Server 2010 team. They said that they are doing much better with releasing electronic documentation (videos, code samples, etc) with 2010. They also said that they know of at least one or two books on InfoPath 2010 that will be published at or around the time that SharePoint 2010 goes RTM, which will probably be 3rd quarter of next year if I had to guess.

3. From SPC09 Las Vegas: Enterprise Mashups with Sharepoint Designer 2010, Bing map services, and Restful web services « Will Lawrence's Blog - October 21, 2009

[…] This function uses the Javascript Client Object Model. Again, the presenter touts the consistency across client side models (.NET, Silverlight, and Javascript). For more information on the Client Object Model, see my blog post. […]

4. A Busy Week in the SharePoint World « The SharePoint Mechanic - February 12, 2010

[…] SPC09 – Working with the new Client Object Model – Courtesy of Will Lawrence […]

5. raj - October 6, 2010

u rock!
I am in SPS2010 traing now and seeing ur blog when i am on client object modal module. This is exactly my trainer is going through now. We were stuck on something, so saw ur blog and it helped.

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

%d bloggers like this: