This document summarizes a presentation about using the Client Object Model in SharePoint 2010 to access SharePoint data from client applications. It discusses the three versions of the Client Object Model for .NET, JavaScript, and Silverlight. Code examples are provided for adding items to a list using each technology. The limitations and advantages of each approach are also covered.
Why Teams call analytics are critical to your entire business
2010 - Developer look at the Client Object Model
1. Melbourne
October 2010
Developer look at the
Client Object Model
Chris O’Connor
Senior Consultant
OBS
www.sharepointroot.com
@grumpywookie
Hashtag : #spsmelbourne
Sponsors
3. Melbourne
October 2010
Remote Calls to SharePoint
History – what we had for SharePoint 2007
Web Services
eg. http://server/_vti_bin/Lists.asmx
New – for SharePoint 2010
Client Object Model
Cut-down version of SharePoint API
Can still use Web Services (and JSON too)
Overview
4. Melbourne
October 2010
Client Object Model
Three (!) versions of Client Object Model
Wrappers for the SharePoint API (DLLs)
Development + coding using :
.NET CLR – C# and VB.NET
Silverlight
JavaScript (ECMAScript)
SharePoint 2010
5. Melbourne
October 2010
Client Object Model
Site Collections and Sites
Lists, List Items, Views, and List Schemas
Files and Folders
Web, List, and List Item Property Bags
Web Parts
Security
Content Types
Site Templates and Site Collection Operations
Supported Areas
8. Melbourne
October 2010
Client Object Model
Visual Studio 2010
SharePoint 2010
Example : News / Announcements
Add to News List (ListItems)
Retrieve & display items from the News List
Demo
9. Melbourne
October 2010
Client Object Model
Windows Application (C#)
Add references
Microsoft.SharePoint.Client
Microsoft.SharePoint.Client.Runtime
Need to deploy these DLL’s with the app
DEMO…>
.NET CLR
10. Melbourne
October 2010
Client Object Model
Other Uses :
Could do the same in a console app
Or VSTO Add-in for Outlook
Notes :
Will run in security context of ‘user’
Sandboxed solutions
Can do asynchronous call+delegate
.NET CLR
11. Melbourne
October 2010
Client Object Model
Create ASCX
Include JavaScript code in mark-up
No code behind, or DLL (class)
ASCX will then be hosted in Master Page
DEMO…>
JavaScript
12. Melbourne
October 2010
Client Object Model
Other Uses :
Include jQuery
Timer + animation – then call ‘next item’
Notes :
<SharePoint:ScriptLink Name="SP.js" runat="server"
OnDemand="true" Localizable="false" />
Optionally : SP.debug.js
JavaScript
13. Melbourne
October 2010
Client Object Model
Limitations of JavaScript
Can only be from SharePoint
Not another site/URL – XSS
Can’t use from a different SP Site either
Light weight
Sandboxed – code if not able to deploy DLL
JavaScript
14. Melbourne
October 2010
Client Object Model
Runs within Silverlight (browser)
Design surface – Canvas, Brush, StackPanel, etc
C# code for SharePoint API
Add DLLs from TEMPLATELAYOUTSClientBin
Microsoft.SharePoint.Client.Silverlight
Microsoft.SharePoint.Client.Silverlight.Runtime
DEMO…>
Silverlight
15. Melbourne
October 2010
Client Object Model
Other Uses :
Highly customised & fluid user interfaces
The sky is the limit
Notes :
Easy with XAP in Document Library
Can be tricky with managing UI thread, etc
Requires Silverlight on client PC (browser plug-in)
Silverlight
16. Melbourne
October 2010
Client Object Model
Wrap-up – quick look at Client Object Model
THREE different versions :
.NET CLR
JavaScript (ECMAScript)
Silverlight
Familiar developer experience (C#)
SharePoint 2010
19. Melbourne
October 2010
Thanks For Listening!
Be sure to submit your feedback
if you want to be in the draw to
win the Xbox 360 and other prizes!
Sponsors
Editor's Notes
SharePoint 2007 Web Services
Some problems
Lots of code
XML + XSD pain
Different to coding with the API
SPSite, SPList, SPListItem, etc
Limited functionality
Performance
The new way in SharePoint 2010
Client Object Model
SharePoint API (DLLs)
Cut-down version
Akin to WPF<->Silverlight
Runs on the client machine (eg. browser)
But there’s more…
Sandboxed Solutions
Sandboxed Solutions
Show the various resources and their locations
Server – Microsoft.SharePoint – [..]\14\ISAPI
.NET – Microsoft.SharePoint.Client – [..]\14\ISAPI
Silverlight – Microsoft.SharePoint.Client.Silverlight – [..]\14\LAYOUTS\ClientBin
ECMAScript – SP.js - [..]\LAYOUTS
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI
Microsoft.SharePoint.Client
Microsoft.SharePoint.Client.Runtime
//get server context - from URL
ClientContext clientCtx = new ClientContext("http://spr:82");
//get web context - like SPWeb
Web web = clientCtx.Web;
clientCtx.Load(web);
//have to exec query
clientCtx.ExecuteQuery();
//get reference to list
List list = web.Lists.GetByTitle("News");
//create a new list item
ListItem listitem = list.AddItem(null);
//add the meta data (properties)
listitem["Title"] = textBox1.Text;
listitem["Body"] = textBox2.Text;
listitem["Expires"] = dateTimePicker1.Text;
//update listitem
listitem.Update();
//show message to user
MessageBox.Show("Added News Item... ");
Need to add tags within SP – eg. ASCX or Master Page
<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" />
OnDemand
Or – can use SP.Debug.js
Limitations of JavaScript
Can only be from SharePoint
Not another site/URL – XSS
Can’t use from a different SP Site either
Light weight
Sandboxed – code if not able to deploy code
Add tags within SP – eg. ASCX or Master Page
OnDemand
SP.Debug.js