Melbourne
October 2010
Developer look at the
Client Object Model
Chris O’Connor
Senior Consultant
OBS
www.sharepointroot.com
@grumpywookie
Hashtag : #spsmelbourne
Sponsors
Melbourne
October 2010
Agenda
SharePoint API – from Client Applications
• Windows Client (WinForm)
• JavaScript (ASCX)
• Silverlight
Code examples + demo
Questions & Answers
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
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
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
Melbourne
October 2010
Client Object Model
Syntax
Melbourne
October 2010
Client.svc
Server
OM
Content
database
JavaScript OM
Proxy
Managed OM
Proxy
.NET CLR / Silverlight
JavaScript Code
XML Request
XML Request
JSON Response
JSON Response
Browser
Managed Client
SharePoint Server
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
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
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
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
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
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
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
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
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
Melbourne
October 2010
Question and
Answer
Question and Answer Time
Client Object Model
Melbourne
October 2010
Related ContentContent + Contact
Slides + demo code (soon !)
http://www.sharepointroot.com
Twitter : @grumpywookie
Email : chris@grumpywookie.com
** GIVEAWAY : MSDN Subscription (!!)
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

2010 - Developer look at the Client Object Model

  • 1.
    Melbourne October 2010 Developer lookat the Client Object Model Chris O’Connor Senior Consultant OBS www.sharepointroot.com @grumpywookie Hashtag : #spsmelbourne Sponsors
  • 2.
    Melbourne October 2010 Agenda SharePoint API– from Client Applications • Windows Client (WinForm) • JavaScript (ASCX) • Silverlight Code examples + demo Questions & Answers
  • 3.
    Melbourne October 2010 Remote Callsto 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 ObjectModel 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 ObjectModel 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
  • 6.
  • 7.
    Melbourne October 2010 Client.svc Server OM Content database JavaScript OM Proxy ManagedOM Proxy .NET CLR / Silverlight JavaScript Code XML Request XML Request JSON Response JSON Response Browser Managed Client SharePoint Server
  • 8.
    Melbourne October 2010 Client ObjectModel 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 ObjectModel 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 ObjectModel 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 ObjectModel 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 ObjectModel 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 ObjectModel 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 ObjectModel 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 ObjectModel 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 ObjectModel Wrap-up – quick look at Client Object Model THREE different versions : .NET CLR JavaScript (ECMAScript) Silverlight Familiar developer experience (C#) SharePoint 2010
  • 17.
    Melbourne October 2010 Question and Answer Questionand Answer Time Client Object Model
  • 18.
    Melbourne October 2010 Related ContentContent+ Contact Slides + demo code (soon !) http://www.sharepointroot.com Twitter : @grumpywookie Email : chris@grumpywookie.com ** GIVEAWAY : MSDN Subscription (!!)
  • 19.
    Melbourne October 2010 Thanks ForListening! 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

  • #4 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…
  • #5 Sandboxed Solutions
  • #6 Sandboxed Solutions
  • #7 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
  • #10 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... ");
  • #12 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
  • #13 Add tags within SP – eg. ASCX or Master Page OnDemand SP.Debug.js