SharePoint Online: Deploy sites to Windows Azure using apps for SharePoint


Office 365, Sharepoint Online, apps for SharePoint
SQL, Windows Azure, SharePoint
Cloud
en-US
3/5/2013
 

Description of the sample

This sample shows you how to upload an autohosted app for SharePoint that includes a SQL Azure database. The database project contains all the tables and data. The app for SharePoint includes a user interface (UI) to search for an employee name in the database.

Prerequisites

This sample requires the following:
  • An Office 365 Developer Site.
  • Visual Studio 2012 and Office Developer Tools for Visual Studio 2012 installed on your computer.

Key components of the sample

The sample zip file contains the following:
  • An O365_SharePointAutoHosted Visual Studio 2012 solution file that contains the AppManifest.xml file and the two projects, O365_SharePointAutoHostedWeb and O365_SharePointAutoHostedDB.
  • The O365_SharePointAutoHostedWeb project includes the following:
    • The Default.aspx file that contains the HTML and ASP.NET controls for the user interface of the app for SharePoint.
    • The Default.aspx.cs file that contains the C# code that connects to the SQL Azure database.
  • The O365_SharePointAutoHostedDB project contains the following:
    • The Employee.sql file that creates a database table.
    • The Script.PostDeployment1.sql file that populates the table with sample data.

Configure the sample

  1. Open Visual Studio 2012 with administrator privileges.
  2. On the File menu, click Open, Project/Solution and then navigate to the folder where you unzipped the O365_SharePointAuthoHosted.sln file, select it and click Open.
  3. Right-click the O365_SharePointAutoHosted solution in the Solution Explorer, click Properties, and on the Property Pages pane, make sure the Multiple startup projects option is selected and then change the Action for the O365_SharePointAutoHostedDB to Start instead of None. This will execute the database project and generate your database when you build the project.
  4. To generate a DACPAC file, right-click the O365_SharePointAutoHostedDB database project in the Solution Explorer, and then click Build. This creates a database with tables and provides you the DACPAC file in the Debug folder if you are working in the Debug mode; otherwise, you should find it in the Release folder. The file path will be similar to [Your application root folder name]\O365_SharePointAutoHostedDB\bin\Debug\O365_SharePointAutoHostedDB.dacpac.
  5. To link your database project to the solution, select the O365_SharePointAutoHosted project in the Solution Explorer and in the Properties pane below the Solution Explorer, click on the down arrow in the SQL Database field and then Select the SQL Package and navigate to the location on your computer where the DACPAC file is located.
  6. In the O365_SharePointAutoHosted Web project, add a SqlAzureConnectionString property in the <appSettings> section of the Web.config file.
    XML  
    <add key="SqlAzureConnectionString" value="Data Source=(localdb)\Projects;
    	Initial Catalog=O365_SharePointAutoHostedDB;Integrated Security=True;
    	Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" /> 
  7. Select the O365_SharePointAutoHosted project in the Solution Explorer and in the Properties pane below, enter the URL of your Office 365 Developer Site into the Site URL property field.

Build the sample

The app for SharePoint can now be uploaded to the App Catalog of a SharePoint Online tenancy. For further debugging, you can deploy the app directly from Visual Studio 2012 to a SharePoint Online website if it was created with the site template. To do this, right-click the O365_SharePointAutoHosted solution in Solution Explorer and select Deploy. Tenant administrators can install the app for SharePoint on their Office 365 Developer Site tenancy by using the following procedure:
  1. Right-click the O365_SharePointAutoHosted solution and select Publish.
  2. On the Publish Summary page select the Open output folder after successful packaging option and then click Finish.
  3. A folder that contains the O365_SharePointAutoHosted.app file opens--note the file location. The file path will be similar to [Your application root folder name]\O365_SharePointAutoHosted\O365_SharePointAutoHosted\O365_SharePointAutoHosted\bin\Debug\app.publish\1.0.0.0\ O365_SharePointAutoHosted.app.

Run and test the sample

  1. Open your Office 365 Developer Site.
  2. On the Developer Site, in the Apps in Testing list, click the plus sign next to the text new app to deploy.
  3. On the Deploy App page, click the link text upload.
  4. Navigate to the location of O365_SharePointAutoHosted.app, select it and click OK.
  5. Click Deploy and on the next dialog click Trust it.
  6. The application will be uploaded to your Office 365 Developer Site.
  7. On your Developer Site, in the Apps in Testing directory, click the O365_SharePointAutoHosted app to run it.
  8. On the page titled "Office 365 Sample Code: SharePoint Auto-Hosted App" you can enter any of the EmployeeNames you find in the Script.PostDeployment1.sql file of the O365_SharePointAutoHostedDB project. You can also enter the character "%" to view all the items in the database.
    The entire list is shown in the following figure.
Figure 1. The employee list.

The list that is displayed by the app.

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
The app fails to upload to Developer Site.
Make sure you entered the Site URL correctly in the configuration steps.
The app does not display content.
Make sure you linked to your DACAP file location properly in the configuration steps.

Change log

Version
Date
First version
February, 28 2013

Related content