Wonderful csom sps barcelona

Post on 16-Apr-2017

499 views 0 download

transcript

Wonderful CSOMSonja MadsenSeptember 26th, 2015

Barcelona

@sonjamadsen sp2013.blogspot.com dev@sonjasapps.com www.sonjasapps.com

Sonja Madsen

Best International Developer

CSOM2007

SSOM

2010 2013

CSOMSharePoint

Foundation

2016 -

Client-Side Object Model

Lists and Libraries

ManagedMetadata

User Profiles

Workflows

Search

Site

Publishing

Analytics

BISocial

Add-ins, apps, farm solutions

_API

CSOM in SharePoint 2013

CSOM advantages over RESTSSOM, JSOM, CSOM with PowerShellWhat’s new

CSOM

DEMO, MVC, the app

JavaScript Silverlight .NETOData

and REST

Lists and Libraries

ManagedMetadata

User Profiles

Workflows

Search

Site

Publishing

Analytics

BI

CSOM

Social

_API

CSOM & REST

Resembles SharePoint Server API, SSOMStrongly typedBatch requestsConnection authentication to the serverRemote error handlingLambda expressionsObject BrowserCovers more SharePoint API than REST

CSOM Advantages

using (var clientContext = spContext.CreateUserClientContextForSPHost())

{

if (clientContext != null)

{

WebCreationInformation creation = new WebCreationInformation();

creation.Url = webTitle;

creation.Title = webTitle;

Web newWeb = clientContext.Web.Webs.Add(creation);

clientContext.Load(newWeb);

clientContext.ExecuteQuery();

}

}

Strongly Typed CSOM

Query.ajax({ url: "http://<site url>/_api/web/webinfos/add", type: "POST", data: JSON.stringify( {'parameters': { '__metadata': { 'type': 'SP.WebInfoCreationInformation' }, 'Url': 'RestSubWeb', 'Title': 'RestSubWeb', 'Description': 'REST created web', 'Language':1033, 'WebTemplate':'sts', 'UseUniquePermissions':false} } ), headers: { "accept": "application/json; odata=verbose", "content-type":"application/json;odata=verbose", "content-length": <length of post body>, "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: doSuccess, error: doError });

Create site with REST

Batch Requests

Context, Web

Add a List

Add a Column

context.Load(…context.ExecuteQuery();

Add anotherColumn

CSOM

REST

_API

REST call form digest value expires after 30 min.

Connection Authentication to the server

Connection Authentication to the server$.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/,,,", method: "POST", headers: { "Accept": "application/json; odata=verbose", "X-RequestDigest": $('#__REQUESTDIGEST').val() }, success: function (data) {}, error: function (data, errorCode, errorMessage) {}});

Structured Remote Exception Handling

Context, Web

Add a List

_api

Add a Column

If the List exists

Add anotherColumn

TRY CATCH

Context, Web

Add a List

Add a Column

Add anotherColumn

FINALLY

DEMO

context.Load(web);

.Where()

.Include()

.OrderBy()

Lambda Expressions

Object Browser

DEMO

Server Side SSOM CSOMusing (SPSite site = new SPSite(projectweburl)) { using (SPWeb web = site.RootWeb) { web.AllowUnsafeUpdates = true; … SPWebTemplate webTemplate = webTemplates[TemplateI]; … //create project site web.Webs.Add(webUrl, webTitle, "", uint.Parse(lcid), webTemplate, false, false); web.Update();

}}

using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { WebCreationInformation creation = new WebCreationInformation(); creation.Url = webTitle; creation.Title = webTitle; Web newWeb = clientContext.Web.Webs.Add(creation);

clientContext.Load(newWeb); clientContext.ExecuteQuery();}}

SSOM CSOMThmxTheme.SetThemeUrlForWeb(siteWeb, currentweb.ServerRelativeUrl + "/_catalogs/theme/SK.thmx"); siteWeb.Update();

siteWeb.ApplyTheme(colorPaletteFile.ServerRelativeUrl, fontSchemeFile.ServerRelativeUrl,null, true); siteWeb.Update(); clientContext.ExecuteQuery();

CSOM with JavaScript = JSOM

using (var context = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) {WebCreationInformation creation = new WebCreationInformation();creation.Url = webTitle;creation.Title = webTitle; Web newWeb = clientContext.Web.Webs.Add(creation);

context.Load(newWeb);context.ExecuteQuery();}}

var context = new SP.ClientContext();

var creation = new SP.WebCreationInformation();

creation.set_title(webTitle);

creation.set_url(webTitle);

creation.set_webTemplate('STS#0');

var newWeb = context.get_web().add(creation);

context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

C#JavaScript

ClientContext context = new ClientContext("http://SiteUrl");

WebCreationInformation creation = new WebCreationInformation();

creation.Url = "webTitle";

creation.Title = "webTitle";

Web newWeb = context.Web.Webs.Add(creation);

context.Load(newWeb);

context.ExecuteQuery();

CSOM with PowerShell

using (var context = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) {WebCreationInformation creation = new WebCreationInformation();creation.Url = webTitle;creation.Title = webTitle; Web newWeb = clientContext.Web.Webs.Add(creation);

context.Load(newWeb);context.ExecuteQuery();}}

C#PowerShell

CSOM Online

What’s New

Microsoft.SharePointOnline.CSOMManage regional settings of a siteManage language settings of a siteManage auditing settings of a siteControl advanced settings for document setsSupport for upcoming enhanced migration APIsControl sandbox solution settings in site collection levelSecondary contact in site collection levelSharing settings

Visual Studio 2015

Summary

JavaScript Silverlight .NETOData

and REST

CSOM

_API

Get stamps from all the sponsorsDeposit the passport to enter the prize raffle

Good luck!

The SPSBCN Passport

FREE BEER!Get your ticket at the registration desk

Network and have fun with your colleagues!

SharePint sponsored by

Michael Collins Pub

Plaça de Sagrada Família

Starts at 19:30h

They help us improve for SharePoint Saturday 2016!

Remember to fill your evaluation forms

Thanks to our Sponsors