You are on page 1of 19

CSOM in SharePoint 2013

Sahil Malik
www.winsmarts.com
Our SPJourney
SharePoint 2013 Basics SharePoint 2013 Behind the Scenes

An Overview of SharePoint Development

PowerShell WSPs Apps

Application Client side technologies


Modules Pages
Feature
Pages CSOM REST
Receivers
WebParts Site Pages

PowerShell List Definitions

CAML & LINQ Content Types


What is CSOM?

Server side object model - Microsoft.SharePoint.*


Has to run on the server
Client side object model Microsoft.SharePoint.Client.*

Client Application
How CSOM works

Create a ClientContext

Use Load/LoadQuery to specify what data you wish to get

Get data using ExecuteQuery/ExecuteQueryAsync

Make changes to data

Save data using ExecuteQuery/ExecuteQueryAsync


How CSOM works

Client Application Server

Sequence of Client.svc
commands:
command 1;
command 2; Execute commands
command 3; in the batch:
XML
context.ExecuteQuery(); command 1;
command 2;
command 3;
JSON
Process results Send results back
ClientContext

Represents the context for SharePoint objects and operations.

Important Load Methods

Important Execute Methods


Client Objects

Server .NET Managed Silverlight JavaScript


(Microsoft (Microsoft.SharePoint (Microsoft.SharePoint (SP.js)
.SharePoint) .Client) .Client.Silverlight)
SPContext ClientContext ClientContext ClientContext

SPSite Site Site Site

SPWeb Web Web Web

SPList List List List

SPListItem ListItem ListItem ListItem

SPField Field Field Field

Member names mostly the same from server to client


(e. g., SPWeb.QuickLaunchEnabled = Web.QuickLaunchEnabled)

JavaScript frequently has get_ set_ methods instead of properties


Load vs LoadQuery
Update Data
ExecuteQuery vs ExecuteQueryAsync
Upload file using CSOM
CSOM Thick Client

Add references to the following DLLs in the ISAPI folder,


Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Runtime.dll
Other such references if you need them.
http://blah.winsmarts.com/2010-3-
Integrating_Silverlight_BING_Maps_with_SharePoint_2010.aspx

Demo

CSOM Thick Client


CSOM Silverlight

Add references to the following DLLs in the _layouts/ClientBin folder,


Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Runtime.dll
Other such references if you need them.
I am going to skip this demo

CSOM Silverlight
http://www.pluralsight.com/training/Courses/TableOfContents/sp2010-client-object-model
CSOM - JavaScript

<%@ Register Tagprefix="SharePoint"


Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=15.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>

<SharePoint:ScriptLink ID="ScriptLink1"
Name="SP.js" runat="server" OnDemand="false"
Localizable="false"
LoadAfterUI="True"></SharePoint:ScriptLink>
Referencing CSOM by hand
Demo

CSOM JavaScript
Summary and Whats next?

A basic intro to REST and CSOM


Deeper dive into CSOM
Deeper dive into REST

Next course: Apps

You might also like