Building a SharePoint Provider-Hosted App for Office365 - Part Two - Creating the Provide-Hosted App

Building a SharePoint Provider-Hosted App for Office365 - Part Two - Creating the Provide-Hosted App

In first part we created the Cert, Token Issuer and App Principal, in this the second post on creating a SharePoint provider-host app we will step through the process I followed and also the steps I took, this app will have no branding and in the third post we will brand the App… let's begin…

Step One

  • New Project - Office/SharePoint - App for SharePoint

Step Two

  • Add your site and choose Provider-hosted app

Step Three

  • Choose what version you would like to point your app to, for this work through I am using SharePoint Online

Step Four

  • Choose the type of web application you would like to create, for this example I am using ASP.NET Web Forms Application

Step Five

  • Unless you would like to configure authenication leave this page as default and click finish

Step Six

  • Configure the App Manifest File
  • Open the AppManifest.xml file

Step Seven

  • On the Permissions tab, specify the Site Collection scope and the Read permission level

Step Eight

  • right-click AppManifest.xml, and then click View Code.

Step Nine

  • Locate the following line of code: <RemoteWebApplication ClientId="66142967‐91BB‐4C50‐9B70‐06375D5240BC" />

  • and Replace it with the clientID you got from the AppPrincipalCreator PowerShell Script you ran in the 1st Post of this series or read the blog again here

Step Ten

  • Configure Web.config file
  • In Solution Explorer, double-click Web.config

Step Eleven

  • Locate the following line of code:

  • and Replace it with the clientID that we put into the AppManifest file above

Step Twelve

  • Delete any markup inside the <body> tag of the Pages/Default.aspx file of your web application

Step Thirteen

  • Add the following HTML and ASP.NET controls inside the <body>
  • This sample uses the UpdatePanel control to enable partial page rendering.

Step Fourteen

  • Open up the Default.apsx.cs code behind file

Step fifteen

  • Add any of the following Using diretives you are missing from your file.

Step Sixteen

  • In the Default.aspx.cs file of your web application, add the variables below inside the Page class.
  • SharePointContextToken contextToken;
    string accessToken;
    Uri sharepointUrl;
    string siteName;
    string currentUser;
    List listOfUsers = new List();
    List listOfLists = new List();

Step Seventeen

  • Add the RetrieveWithCSOM method inside the Page class. This method uses the SharePoint CSOM to retrieve information about your site and display it on the page.

Step Eighteen

  • Add the CSOM_Click method inside the Page class. This method triggers the event that occurs when the user clicks the Populate Data link.

Step Nineteen

  • Replace the existing Page_Load method. The Page_Load method uses methods in the TokenHelper.cs file to retrieve the context from the Request object and get an access token from Microsoft Azure Access Control Service (ACS).

  • From this

  • To this

Step Twenty

  • Let's TEST !!!! Press the F5

Step Twenty One

  • Say "YES"

Step Twenty Two

  • Click "Trust It"

Step Twenty Three

  • Click on Populate Data

Step Twenty Four

  • and there we have it...