Saturday, August 22, 2015

SharePoint 2013: Hello World remote app using REST

This has been removed. Please use the sample at: SharePoint Add-in REST\OData Basic Data perations. The description below does not apply to the new sample.


Summary: Learn how to create a basic "hello world" provider-hosted app for SharePoint that uses the SharePoint REST interface to read information about a SharePoint 2013 site from a remote web application.

Description of the sample

The sample demonstrates how to read data that conforms with the OData protocol from the REST endpoints where the basic SharePoint entities, such as lists and users, are exposed. Additionally, it demonstrates how to parse Atom-formatted XML returned from these endpoints.
The code that uses the REST APIs is located in the Home.aspx.cs file of the BasicSelfHostedAppRESTWeb project. The following screen shot shows how the Home.aspx page in the app appears after you install and launch the app.
Figure 1. Home.aspx page in the Hello World remote app for SharePoint using REST

Basic self-hosted app launch page For more information about the SharePoint REST APIs, see Programming using the SharePoint 2013 REST service. For more information about working with JSON, Atom, and OData, see OData: JavaScript Object Notation (JSON) Format and OData: AtomPub Format.

Prerequisites

This sample requires the following:
  • A SharePoint 2013 development environment that is configured for app isolation and OAuth
  • Visual Studio 2012 and Office Developer Tools for Visual Studio 2012 installed on your developer computer
  • Basic familiarity with RESTful web services

Key components of the sample

The sample app contains the following:
  • BasicSelfHostedAppREST project, which contains the AppManifest.xml file
  • BasicSelfHostedAppRESTWeb project, which contains the following:
    • 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 REST APIs to read and write data to and from the parent web
    • web.config file

Configure the sample

To configure the Hello world remote app using REST sample, update the SiteUrl property of the solution with the URL of the home page of your SharePoint 2013 site.

Build the sample

Press F5 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. Choose Populate Data to see some basic information about the parent web.

Example

The following figure shows an example of the kinds of information that this sample app can read and display.
Figure 2. View populated data about the parent web

Basic self-hosted app with data populated

Troubleshooting

The following table lists common configuration and environment errors that prevent the sample from running or deploying properly and how you can solve them.
Problem
Solution
Visual Studio does not open the browser after you press the F5 key.
Set the app for SharePoint project as the startup project.
HTTP error 405 Method not allowed.
Locate the applicationhost.config file in %userprofile%\Documents\IISExpress\config.
Locate the handler entry for StaticFile, and add the verbs GET, HEAD, POST, DEBUG, and TRACE.

Change log

Version
Date
First version
July 16, 2012

Related content

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