Saturday, August 22, 2015

SharePoint 2013: Perform basic data access operations by using CSOM in apps

This sample has been moved to SharePoint-Add-in-CSOM-BasicDataOperations.

The sample demonstrates how to read and write list and list item data by using objects and methods in the SharePoint 2013 client object model (CSOM). Additionally, it demonstrates how to obtain the context and access tokens that are necessary for reading and writing data in a provider-hosted app for SharePoint.
The code that uses the CSOM is located in the Home.aspx.cs file of the BasicDataOperationsWeb project. The following screen shot shows how the Home.aspx page of the app appears after you install and launch the app.
Figure 1. Home.aspx page in the app, which displays the controls for viewing and adding lists to and from the parent web

Prerequisites

This sample requires the following:
  • A SharePoint 2013 development environment that is configured for app isolation and OAuth
  • Visual Studio 2012 and SharePoint development tools in Visual Studio 2012 installed on your developer computer
  • Basic familiarity with the SharePoint CSOM and C#

Key components of the sample

The basic data operations sample app contains the following:
  • BasicDataOperations project, which contains the AppManifest.xml file
  • BasicDataOperationsWeb project
    • Home.aspx file, which contains the HTML and ASP.NET controls for the app’s user interface.
    • Home.aspx.cs file, which contains the C# code that uses the SharePoint CSOM to read and write data
    • web.config file

Configure the sample

To configure the perform basic data operations by using CSOM sample app, update the SiteUrl property of the solution with the URL of the home page of your SharePoint 2013 site.

Build the sample

Press the F5 key to build and deploy the app.

Run and test the sample

  1. Choose Trust It on the consent page to grant permissions to the app.
  2. Use the app’s interface to read, create, and update lists and add list items on the parent SharePoint 2013 site.

Examples

The following figure shows an example of how to use this app for SharePoint to view list items.
Figure 2. View list items from a list on the parent web

The following figure shows an example of how to use this app for SharePoint to add list items.
Figure 3. Add list items to a list on the parent web

No comments:

View Tenant (ULS) Logs in SharePoint Online using CSOM

Even though the classes exist in the CSOM, the Microsoft Office 365 Engineering team has confirmed that this is something which is not poss...