1 / 33

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

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.

kipp
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Overview of Data Technologies Strongly-typed lists Methods, MOSS Weakly-typed lists ClientOM Web Services REST APIs Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed lists LINQ Strongly-typed lists New in 2010 Improved

  3. Agenda • Client Object Model • The Basics • Queries • Exception Scopes • Conditional Load • Silverlight Cross-site Data Access

  4. 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

  5. Starting with the client OM .NET CLR: 14\ISAPI Silverlight: 14\TEMPLATE\LAYOUTS\ClientBin • Packaged .XAP coming post-beta JavaScript: • Use <ScriptLink>/SP.SOD.execute to add JS files

  6. Getting Started: 3 things to know 1. 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 = new ClientContext(“http://mysite”); clientContext.Load(list); clientContext.ExecuteQuery();

  7. Hello World, Client Object Model

  8. 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, ClientRequestSucceededEventArgsargs) • { • web.Title = web.Title + " + Silverlight"; • web.Update(); • context.ExecuteQueryAsync(SayDone, null); • }

  9. JavaScript • var context; • varweb; • 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); • }

  10. Accessing Data with Client OM Client Application Client Application WPF/WinForm/Office Silverlight JavaScript Client OM client ExecuteQuery() XML server JSON Web Service Client.svc Server Application SharePoint API SharePoint Data

  11. Major Objects in Client Object Model Site Web ContentType Change List Navigation Form NavigationNode View UserCustomAction Field RoleDefinition ListItem RoleAssignment Folder User Interface WorkflowAssociation Data and Schema File WorkflowTemplate Logic WebPart Security

  12. Items not covered by CSOM • User Profiles • People • Search • Enterprise Metadata • Excel REST web services • Publishing • Administration

  13. 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

  14. 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)

  15. Web Properties: Default Operations boolAllowRssFeeds boolAllowRssFeeds boolAllowRssFeeds Group AssociatedMemberGroup DateTimeCreated ContentTypeCollectionContentTypes DateTimeCreated DateTimeCreated User CurrentUser String Description String Description String Description GuidId GuidId GuidId FieldCollectionFields List Lists boolRecycleBinEnabled List Lists boolRecycleBinEnabled boolRecycleBinEnabled Folder RootFolder String Title Folder RootFolder String Title String Title clientContext.Load(web); clientContext.Load(web.RootFolder); clientContext.Load(web.Lists);

  16. Advanced queries using Linq

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

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

  19. Query Modes: Fill vs. Query • “Fill”: context.Load(object, paramsLinqExpression) • 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

  20. 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 .IncludeWithDefaultPropertiesfor default + custom properties) • Use .Take method to: • Restrict overall number of items retrieved

  21. Queries and Filtering

  22. 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

  23. Exception Handling & Conditional Load

  24. 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

  25. Browser Page (http://sharepoint/page.aspx) 2. Page is instantiated with special token Silverlight XAP (http://scrum/myscrum.xap) 3. XAP calls back to custom web service on host server, with token client server http://sharepoint http://scrum 1. Web Part is added to page with application markup that indicates host server is http://scrum 4. App server can forwards client OM request on behalf of user

  26. Cross-site data access: core concepts Application 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

  27. Cross-Site Data Access

  28. Getting Started: 3 things to know 1. 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 = new ClientContext(“http://mysite”); clientContext.Load(list); clientContext.ExecuteQuery();

  29. Overview of Data Technologies Strongly-typed lists Methods, MOSS Weakly-typed lists ClientOM Web Services REST APIs Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed lists LINQ Strongly-typed lists New in 2010 Improved

  30. YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation forms online at MicrosoftPDC.com

  31. 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/learn Built by Developers for Developers….

More Related