developing solutions for microsoft sharepoint server 2010 using the client object model

33
Developing Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model Mike Ammerlaan Program Manager Microsoft Corporation PR07

Upload: ulla

Post on 15-Feb-2016

54 views

Category:

Documents


0 download

DESCRIPTION

PR07. Developing Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model. Mike Ammerlaan Program Manager Microsoft Corporation. Overview of Data Technologies. Strongly-typed lists. Methods, MOSS. Weakly-typed lists. Client OM. Web Services. REST APIs. Client-side. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Developing Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model Mike AmmerlaanProgram ManagerMicrosoft Corporation

PR07

Page 2: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Overview of Data Technologies

LINQ

Farm

Site

List Data

External Lists

Data Platform

Client-side

Server-side

Strongly-typed listsWeakly-typed lists

Strongly-typed lists

Weakly-typed listsServer OM

Client OM REST APIs

New in 2010Improved

Web Services

Methods, MOSS

Page 3: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Agenda

>Client Object Model>The Basics>Queries>Exception Scopes>Conditional Load>Silverlight Cross-site Data

Access

Page 4: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Client Object Model: The Basics> Client-side library for remotely calling

SharePoint> Mirrors (a subset) of objects on the server> Usable in JavaScript, .net CLR, Silverlight

CLR

> Requests are batched for over-the-wire performance

> Used by SharePoint UI for operations like batch deletion

Page 5: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Starting with the client OM.NET CLR: 14\ISAPI

Silverlight: 14\TEMPLATE\LAYOUTS\ClientBin

> Packaged .XAP coming post-betaJavaScript:

> Use <ScriptLink>/SP.SOD.execute to add JS files

Microsoft.SharePoint.Client 281kbMicrosoft.SharePoint.Client.Runtime

145kb

SP.js 380kbSP.Core.js 13kbSP.Runtime.js 68kb

Page 6: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Getting Started: 3 things to know1. ClientContext is the central object

2. Before you read a property, you have to ask for it

3. All requests must be committed in a batch

clientContext.Load(list);

clientContext.ExecuteQuery();

clientContext = new ClientContext(“http://mysite”);

Page 7: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Hello World, Client Object Model

Page 8: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

C#private ClientContext context;private Web web;

private void TestButton_Click(object sender, RoutedEventArgs e){

context = ClientContext.Current;web = context.Web;context.Load(web);context.ExecuteQueryAsync(TitleRetrievedContinue, null);

}

private void TitleRetrievedContinue(object sender, ClientRequestSucceededEventArgs args){

web.Title = web.Title + " + Silverlight";web.Update();context.ExecuteQueryAsync(SayDone, null);

}

Page 9: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

JavaScriptvar context;var web;

function testButtonClick(){

context = new SP.ClientContext();web = context.get_web();context.load(web)context.executeQueryAsync(titleRetrievedContinue);

}

function titleRetrievedContinue(){

web.set_title(web.get_title() + " + JavaScript");web.update();context.executeQueryAsync(sayDone);

}

Page 10: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Accessing Data with Client OM

Client Application

Client Application

Client OM

JSONExecuteQuery()

XML

WPF/WinForm/OfficeSilverlightJavaScript

SharePoint Data

SharePoint API

Web Service

ServerApplication

Client.svc

clientserver

Page 11: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Site

Web

ListItem

Field

View

Form

Folder

List

NavigationNode

Navigation

UserCustomAction

ContentType

RoleDefinition

WorkflowAssociationWorkflowTemplate

RoleAssignment

Change

WebPart

File

User Interface

Data and Schema

Security

Logic

Major Objects in Client Object Model

Page 12: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Items not covered by CSOM

> User Profiles> People> Search> Enterprise

Metadata

> Excel REST web services

> Publishing> Administration

Page 13: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Client Object Model Limitations> Client object model cannot be used on

server to talk to same-server> You still need to handle synch/update

semantics (change log could help)> No elevation of privilege capabilities> Requests are throttled> .net CLR has sync method;

Silverlight CLR and Jscript are async

Page 14: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Retrieval Queries> By default, .Load will fetch most*

simple properties of an object> Explicitly need to retrieve client objects or

child collections> You can use Linq to further define the

shape of your queries> What properties to include> What sub-objects to retrieve> (List items still need to use CAML queries)

Page 15: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Web Properties: Default Operationsbool AllowRssFeeds

DateTime CreatedContentTypeCollection ContentTypes

Guid IdFieldCollection Fields

Group AssociatedMemberGroup

User CurrentUser String Description

List Lists

Folder RootFolder String Title

bool RecycleBinEnabled

clientContext.Load(web);

bool AllowRssFeeds

DateTime Created

Guid Id

String Description

String Title

bool RecycleBinEnabled

bool AllowRssFeeds

DateTime Created

Guid Id

String Description

String Title

bool RecycleBinEnabled

clientContext.Load(web.RootFolder);clientContext.Load(web.Lists);

List Lists

Folder RootFolder

Page 16: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Advanced queries using Linq

Page 17: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Query Syntax

var query = from list in clientContext.Web.Lists         where list.Title != null         select list; var result = clientContext.LoadQuery(query);

clientContext.ExecuteQuery();

Page 18: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Method Syntax

clientContext.Load(oList,list => list.Fields .Where(field => field.Hidden == false && field.Filterable == true));

clientContext.ExecuteQuery();

Page 19: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Query Modes: Fill vs. Query> “Fill”:

context.Load(object, params LinqExpression)> Fills out the objects in the context: in-

place> ‘method syntax’ linq

> “Query”:context.LoadQuery(IQueryable)> Use linq query to return custom objects> Not filled into the context> ‘query syntax’ and ‘method syntax’ linq

Page 20: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Method Query Syntax Basics> Use .Where method to:

> Filter down items retrieved in a collection

> Use .Include method to:> Explicitly select properties or child objects

to retrieve> You own specifying what you want!

> (use .IncludeWithDefaultProperties for default + custom properties)

> Use .Take method to:> Restrict overall number of items retrieved

Page 21: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Queries and Filtering

Page 22: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Client Object Model Advanced Topics

> Exception Handling> Use to react to exceptions within a batch

> Conditional Scope + Retrieves> Use to check conditions before doing loads,

on the server within a batch

> Uses scopes and using statements (IDisposable) to signify how methods are filtered

Page 23: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Exception Handling & Conditional Load

Page 24: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Silverlight Cross-Site Data Accessusing the Client Object Model

> The Problem:> You want to host powerful apps on

SharePoint that use data on another server

> You want to minimize impact to SharePoint deployments

> Silverlight is (generally) limited to calls on one domain

> One solution: host XAP on external server & delegate user token

Page 25: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

clientserver

Browser Page (http://sharepoint/page.aspx)

http://sharepoint

Silverlight XAP(http://scrum/myscrum.xap)

1. Web Part is added to page with application markup that

indicates host server is http://scrum

2. Page is instantiated with special

token 3. XAP calls back to custom web service on host server, with

token

http://scrum4. App server can forwards

client OM request on

behalf of user

Page 26: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Cross-site data access: core conceptsApplication Principal

> SPUser that represents the incoming request account

> Effective permissions of Silverlight w/ client OM = Permissions of App Principal & Initiating User

Application XML> Contains hosting server information

External Application Provider> Can be deployed to host server to provide

customized application-add experience

Request Forwarder> Code deployed to remote server to forward

requests

Page 27: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Cross-Site Data Access

Page 28: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Getting Started: 3 things to know1. ClientContext is the central object

2. Before you read a property, you have to ask for it

3. All requests must be committed in a batch

clientContext.Load(list);

clientContext.ExecuteQuery();

clientContext = new ClientContext(“http://mysite”);

Page 29: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Overview of Data Technologies

LINQ

Farm

Site

List Data

External Lists

Data Platform

Client-side

Server-side

Strongly-typed listsWeakly-typed lists

Strongly-typed lists

Weakly-typed listsServer OM

Client OM REST APIs

New in 2010Improved

Web Services

Methods, MOSS

Page 30: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation

forms online atMicrosoftPDC.com

Page 31: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

Learn More On Channel 9> Expand your PDC experience through

Channel 9

> Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses

channel9.msdn.com/learnBuilt by Developers for Developers….

Page 32: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 33: Developing  Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model