1 / 20

Working with SharePoint 2010 Client Object Model in .NET Applications

Learn how to access and manipulate SharePoint data in remote applications using the SharePoint 2010 Client Object Model in .NET. This module covers the architecture, processes, and development techniques for .NET, Silverlight, and JavaScript clients.

nmurphy
Download Presentation

Working with SharePoint 2010 Client Object Model in .NET Applications

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. Module 8 Working with Client-Based APIs for SharePoint 2010

  2. Module Overview • Overview of the SharePoint 2010 Client Object Model • Working with the SharePoint 2010 Client Object Model in .NET Applications • Lab: Developing .NET Applications Using the SharePoint Client Object Model

  3. Lesson 1: Overview of the SharePoint 2010 Client Object Model • Accessing SharePoint Data in Remote Applications • Client Object Model Architecture • Client Object Model Processes • Developing .NET Clients for the SharePoint Client Object Model • Developing Silverlight Clients for the SharePoint Client Object Model • Developing JavaScript Clients for the SharePoint Client Object Model

  4. Accessing SharePoint Data in Remote Applications • Rationale • Remote applications that do not run on SharePoint can still consume SharePoint objects and data • Scenarios • Windows applications • Console applications • ASP.NET applications • Silverlight hosted in non-SharePoint Web sites • Silverlight out-of-browser applications • JavaScript clients (such as ribbon controls and client-side dialogs

  5. Client Object Model Architecture REST APIs Strongly-typed lists Client OM Weakly-typed lists Client-side Data Platform Farm Site List Data External Lists Server-side

  6. Client Object Model Processes Client Application Server Sequence of commands: command 1; command 2; command 3; context.ExecuteQuery(); client.svc Execute commands in the batch: command 1; command 2; command 3; Send results back XML JSON Process results

  7. Developing .NET Clients for the SharePoint Client Object Model • Reference DLLs from the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI folder • Microsoft.SharePoint.Client.dll • Microsoft.SharePoint.Client.Runtime.dll • Distribute the DLLs with your application • Setup projects • Choose between synchronous and asynchronous execution

  8. Developing Silverlight Clients for the SharePoint Client Object Model • Reference DLLs from the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder • Microsoft.SharePoint.Client.Silverlight.dll • Microsoft.SharePoint.Client.Silverlight.Runtime.dll • Distribute the DLLs with your application • XAP files • Choose between synchronous and asynchronous execution • Only asynchronous execution allowed on the Silverlight main UI thread

  9. Developing JavaScript Clients for the SharePoint Client Object Model • Reference the Client Object Model in the sp.js file using a ScriptLink object • Use asynchronous execution for responsive user interfaces <SharePoint:ScriptLink ID="showDialog" runat="server" Name="sp.js" Localizable="false" LoadAfterUI="true" />

  10. Lesson 2: Working with the SharePoint 2010 Client Object Model in .NET Applications • Creating ClientContext Objects • Loading Webs • Creating Webs • Loading and Creating Lists • Working with List Data • Calling ExecuteQuery and ExecuteQueryAsync Methods • Disposing of ClientContext Objects

  11. Creating ClientContext Objects • ClientContext objects provide the entry point to the SharePoint 2010 client object model • Instantiating ClientContext objects //Instantiate a ClientContext ClientContextremoteCtx = new ClientContext("http://sharepoint"); //Then start loading objects, such as Webs //At some point, ExecuteQuery needs to be called

  12. Loading Webs • The Web object is the client equivalent of the server-side SPWeb object • A Web object must be loaded by the ClientContext object before it can be used • The ClientContext object has a Web property, much like the SPContext server-side object has a Current.Web property //Instantiate a ClientContext ClientContextremoteCtx = new ClientContext("http://sharepoint"); //Then start loading objects, such as Webs Web remoteWeb = remoteCtx.Web; remoteCtx.Load(remoteWeb); //At some point, ExecuteQuery needs to be called

  13. Creating Webs • WebCreationInformation objects are used to set required and optional properties in the Web-creation process • WebCreationInformation objects are passed into the Webs.Add() method • Web is only created when ExecuteQuery is called WebCreationInformationskillsInfo = new WebCreationInformation(); skillsInfo.Title = "Skills Matrix"; skillsInfo.Language = 1033; skillsInfo.WebTemplate = "STS#1"; skillsInfo.Url = "Skills"; skillsInfo.UseSamePermissionsAsParentSite = true; Web skillsWeb = remoteWeb.Webs.Add(skillsInfo); skillsWeb.QuickLaunchEnabled = true; remoteCtx.ExecuteQuery();

  14. Loading and Creating Lists • The List object is the client equivalent of the server-side SPList object • Reference an existing List as a member of a Web.Lists collection • Create and reference a new List by calling the Lists.Add method of a Web object and pass in a ListCreationInformation object • A List object must be loaded by the ClientContext object before it can be used ListCreationInformationskillDefInfo = new ListCreationInformation(); skillDefInfo.TemplateType = (int)ListTemplateType.GenericList; skillDefInfo.Title = "Skills"; skillDefInfo.QuickLaunchOption = QuickLaunchOptions.On; List skillDef = skillsWeb.Lists.Add(skillDefInfo); skillDef.Fields.AddFieldAsXml(@"<Field Type='Text' DisplayName='Description'/>", true, AddFieldOptions.DefaultValue); remoteCtx.ExecuteQuery(); remoteCtx.Load(skillDef); remoteCtx.ExecuteQuery();

  15. Working with List Data • The ListItem object is the client equivalent of the server-side SPListItem object • Reference an existing ListItem as a member of a ListItemCollection object • Create and reference a new ListItem by calling the AddItem method of a List object and pass in a ListItemCreationInformation object • Set member values of the ListItem to update fields • Call Update to save changes to list items ListItemCreationInformationskillInfo = new ListItemCreationInformation(); ListItem skill = skillDef.AddItem(skillInfo); skill["Title"] = "Write Reports"; skill["Importance"] = "Optional"; skill.Update(); remoteCtx.ExecuteQuery();

  16. Calling ExecuteQuery and ExecuteQueryAsync Methods • ExecuteQuery is a synchronous method • Client code execution halts until SharePoint has executed the batched commands and has responded • ExecuteQueryAsync is an asynchronous method • Client code execution continues while SharePoint executes the batched commands • Results of the SharePoint operations are surfaced in callback procedures • Success callback procedures • Failure callback procedures

  17. Disposing of ClientContext Objects • When you have finished with ClientContext objects, you should dispose of them • Typically in a try-finally construct ClientContextremoteCtx = null; try { remoteCtx = new ClientContext("http://sharepoint" // Perform required operations // ... } catch(Exception clientEx) { // Handle any exceptions } finally { remoteCtx.Dispose(); }

  18. Lab: Developing .NET Applications Using the SharePoint Client Object Model • Exercise 1: Creating a SharePoint 2010 Site, List, and List Items Using the Client Object Model • Exercise 2: Building and Using the Console Application Logon information Estimated time: 45 minutes

  19. Lab Review • Which folder contains the Client Object Model DLLs? • What object provided you with an entry point into the SharePoint Client Object Model? • What SharePoint objects did you work with in the lab?

  20. Module Review • In this module, you have learned: • About the scenarios and technologies supported by the SharePoint 2010 Client Object Model • To work with the SharePoint 2010 Client Object Model in .NET applications

More Related