• Save
SharePoint Saturday The Conference DC - How the client object model saved the day
Upcoming SlideShare
Loading in...5
×
 

SharePoint Saturday The Conference DC - How the client object model saved the day

on

  • 1,167 views

 

Statistics

Views

Total Views
1,167
Views on SlideShare
1,167
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

SharePoint Saturday The Conference DC - How the client object model saved the day SharePoint Saturday The Conference DC - How the client object model saved the day Presentation Transcript

  • How the Client ObjectModel Saved the Day!Liam ClearySolution Architect | SharePoint MVP
  • About Me• Solution Architect @ SusQtech (Winchester, VA)• SharePoint MVP since 2007• Working with SharePoint since 2002• Worked on all kinds of projects • Internet • Intranet • Extranet • Anything SharePoint Really• Involved in Architecture, Deployment, Customization and Development of SharePoint
  • It is a wise man who knowswhere courage ends andstupidity begins.Jerome Cady – Hollywood Screenwriter View slide
  • Agenda• Data Access In SharePoint • SharePoint 2007 • SharePoint 2010• What is the Client Object Model? • Managed Code • Silverlight • ECMAScript• How can we use it?• How did it save the day?• NOTE: Not a heavy code session, well we will see!! View slide
  • Data Access In SharePoint 2007• Historically we were tied to direct API or Web Services SharePoint Database SharePoint API Server Applications Web Services (Native / Custom) Client Applications
  • Problems• Out of the box Web Services may not have the required methods• Custom Web Services can be very complicated to create• API is not rich enough • Custom API wrappers are created • Seen this again and again• Complicated to all from JavaScript / jQuery• Client Applications if developed are all custom, even data access• Applications are not really developed• See the same issues with every client
  • Data Access In SharePoint 2010• Updated for SharePoint 2010 • Similar Approach with a few tweaks SharePoint Database SharePoint API Web Services Client Object Model (Native / Custom) Client Applications Server Applications
  • What is the Client Object Model?• “Knight in Shining Armor” for client application development• Simple and easy to use API• Consistent implementations• Abstracted methods from core API • Subset of the Types and Members from Microsoft.SharePoint namespace• Three flavors • .NET CLR • Silverlight • ECMAScript (JavaScript, Jscript)• Easy to Consume data from SharePoint
  • Client Object Model Browser Based ECMA Script (JavaScript) ECMA Script Object Model SharePoint Server Object Model Proxy Client Services Client Proxy SQL Server Content Databases Managed Object Model .NET Managed (.NET & Silverlight)
  • Client Object Model – Process• Data is retrieved in a specific way Client Application Server Commands Client.svc XML context.ExecuteQuery(); Commands JSON Process Results Send Back Results
  • Client Object Model - Objects • Similar to core API • Naming slightly changed • Consistent across all implementationsServer .NET Managed Silverlight JavaScript(Microsoft.SharePoint) (Microsoft.SharePoint.Client) (Microsoft.SharePoint.Cliernt.Silverlight) (SP.js)SPContext ClientContext ClientContext ClientContextSPSite Site Site SiteSPWeb Web Web WebSPList List List ListSPListItem ListItem ListItem ListItemSPField Field Field Field
  • Client Object Model – Getting Started• No ClientContext = No ConnectionclientContext = new ClientContext(“http://mysharepointsite.com”);• Need to LOAD before you can READclientContext.Load(web);clientContext.Load(web.Lists);• Must COMMIT requests in a BATCHclientContext.ExecuteQuery();clientContext.ExecuteQueryAsync(succeedcallback, failurecallback);
  • Client Object Model – Object Identities• Used to batch up objects that can be used before the “ExecuteQuery”ClientContext clientContext = new ClientContext(“http://siteurl”);List list = clientContext.Web.Lists.GetByTitle(“ListName”);CamlQuery camlQuery = new camlQuery();camlQuery.ViewXml = “<View/>”;ListItemCollection listItems = list.GetItem(camlQuery);clientContext.Load(list);clientContext.Load(listItems);clientContext.ExecuteQuery();• Once the objects have been set and executed they can be iterated throughforeach(ListItem listItem in listItems) Console.WriteLine(“Title: ,1-”, listItem*“Title”+,
  • Client Object Model – Lambda Expressions• Used trim results, filter or even increase performance Trimming ClientContext clientContext = new ClientContext("http://siteurl"); Web site = clientContext.Web; clientContext.Load(site, s => s.Title, s => s.Description); clientContext.ExecuteQuery(); Filter ClientContext clientContext = new ClientContext("http://siteurl"); ListCollection listCollection = clientContext.Web.Lists; IEnumerable<List> hiddenLists = clientContext.LoadQuery( listCollection . Where(list => !list.Hidden && list.BaseType == BaseType.DocumentLibrary)); clientContext.ExecuteQuery(); Performance ClientContext clientContext = new ClientContext("http://siteurl"); IEnumerable<List> lists = clientContext.LoadQuery( clientContext.Web.Lists.Include( list => list.Title, list => list.Hidden, list => list.Fields.Include( field => field.Title, field => field.Hidden))); clientContext.ExecuteQuery();
  • Client Object Model – Asynchronous Processing• Ability to invoke intensive queries Asynchronously delegate void AsynchronousDelegate(); Public void Run() { ClientContext clientContext = new ClientContext("http://siteurl"); ListCollection lists = clientContext.Web.Lists; IEnumerable<List> newListCollection = clientContext.LoadQuery( lists.Include( list => list.Title)); AsynchronousDelegate executeQueryAsynchronously = new AsynchronousDelegate(clientContext.ExecuteQuery); executeQueryAsynchronously.BeginInvoke( arg => { clientContext.ExecuteQuery(); foreach (List list in newListCollection) Console.WriteLine("Title: {0}", list.Title); }, null); }
  • Client Object Model - .NET• Provides easy access from remote .NET Clients to SharePoint Data• Can be used from Managed Code such as Office• Utilizes the following Assemblies • Microsoft.SharePoint.Client.dll (281 KB) • Microsoft.SharePoint.Client.Runtime.dll (145 KB)• Compared to Microsoft.SharePoint.dll (15.3 MB)• SQL Like• Batch Processing
  • Client Object Model – Managed CodeDEMO
  • Client Object Model - Silverlight• Use Silverlight on page or in a web part• Web Part can contain custom properties by using the “InitParams” property• XAP file deployed to Layouts or Content Database• Once the Silverlight is loaded it can access the Client Object Model• Stored in the “14TEMPLATELAYOUTSClientBin” directory• Utilizes the following Assemblies • Microsoft.SharePoint.Client.Silverlight.dll (262 KB) • Microsoft.SharePoint.Client.Silverlight.Runtime.dll (138 KB)• Must call “clientContext.ExecuteQueryAsync”
  • Client Object Model – Silverlight (WPF)DEMO
  • Client Object Model - ECMAScript• Page needs to load the “SP.js” • Use <SharePoint:ScriptLink>• Can use debug version • Use <SharePoint:ScriptLink …ScriptMode=“Debug”>• Client Context can be set using var clientContext = new SP.ClientContext.get_current(); Or var clientContext = new SP.ClientContext();• SAVE TIME NOTE: Properties are case sensitive• SP.js (381 KB), SP.Debug.js (561 KB)
  • Client Object Model – ECMAScriptDEMO
  • Client Object Model – Wrap-up• .NET CLR has a Sync Method whereas Silverlight CLR and JavaScript are Asynchronous• All requests are throttled, so be aware of performance• No ELEVATION of privilege capabilities • SPSecurity.RunWithElevatedPrivileges• Must handle the Synchronize and Update logic• Need to handle the efficient loading etc. of objects • Use LINQ • Use Lambda Expressions• Works well however an element of developer experience is needed to use
  • Client Object Model – How did it save the day?• Quickly update multiple items on SharePoint • No direct Server Access • Using Forms Login also• Add “cool” functionality easily using ECMA Script • Inline editing• Able to track my wifes spending via SharePoint • Used Client Object Model to remotely check SharePoint list for expenditure and alert on desktop• Completely made up, but the reality is that simple, this could be done, as long as the data feed is available this is achievable
  • Thank You• Personal Email: liamcleary@msn.com• Work: http://www.susqtech.com• Twitter: @helloitsliam• Blog: www.helloitsliam.com