Deploy SharePoint Hosted Add-In (App) To SharePoint Online In Office 365

SharePoint hosted add-in (app) is one of the two ways to create SharePoint add-ins, the other one being Provider Hosted Add-ins. SharePoint hosted add-ins can be used to deploy lists, custom pages,workflows, web parts and other components. We can have only JavaScript code in the pages that are deployed along with SharePoint Hosted add-in. In order to ensure that we have the required templates go to Visual Studio. From Office/SharePoint section check if the ‘SharePoint Add-in’ template is available. If it is not present we will have to install Office developer tools to add the SharePoint 2016 templates along with Office Templates. You can check out how to set up the Visual Studio environment for SharePoint 2016 here.

Once the visual studio templates for SharePoint 2016 are made available let’s get started with SharePoint hosted add-in creation. From Visual Studio select the SharePoint Add-in and specify the add-in name.

Visual

Mention the Office 365 SharePoint Online developer site URL and select the SharePoint Add-in radio button.

Visual

On clicking Next, it will pop up the Office 365 Authentication Window.

SharePoint

Click on Sign in. Specify the SharePoint Target version as SharePoint Online and click on Finish.

SharePoint

It will establish a communication with SharePoint and create the SharePoint Add-in project structure.

SharePoint

The SharePoint Hosted Add-in Solution structure will like below.

SharePoint

We can add SharePoint Components like Applicationpages,Lists,Workflows etc. by right clicking the Solution. Select New Item and click on Add.

SharePoint

This will provide us the options that can be added to the project. For the time being I am trying to deploy a List with some prepopulated data to SharePoint Online as an Add-in.

SharePoint

Select List and specify the list name. Click on Add. Specify the type of List we are trying to create. In this case it is a normal custom list. Click on Finish.

SharePoint

It will add the list. Now we can add new columns and specify the data type using the UI. I have added the below columns to the list.

  • Employee Name
  • Employee Address
  • Previous Company
  • Experience
SharePoint

We can add default data to the list instance by clicking on the Elements.xml file of the list instance. Each Row field will indicate a SharePoint List item and the Field tag represents the column within the list.
  1. <Data>  
  2. <Rows>  
  3. <Row>  
  4. <FieldNameFieldName="Employee Name">Rajesh</Field>  
  5. <FieldNameFieldName="Employee Address">Kochi,India</Field>  
  6. <FieldNameFieldName="Previous Company">UB Group</Field>  
  7. <FieldNameFieldName="Experience">4</Field>  
  8. </Row>  
  9. <Row>  
  10. <FieldNameFieldName="Employee Name">Jinesh</Field>  
  11. <FieldNameFieldName="Employee Address">Bangalore,India</Field>  
  12. <FieldNameFieldName="Previous Company">IBM</Field>  
  13. <FieldNameFieldName="Experience">12</Field>  
  14. </Row>  
  15. </Rows>  
  16. </Data>  
<Data /> <rows> <row> <fieldname="employee Name">Rajesh</field> <fieldname="employee Address">Kochi,India</field> <fieldname="previous Company">UB Group</field> <fieldname="experience">4</field> </row> <row> <fieldname="employee Name">Jinesh</field> <fieldname="employee Address">Bangalore,India</field> <fieldname="previous Company">IBM</field> <fieldname="experience">12</field> </row> </rows> </data>

Now we have to change the start page of the SharePoint Hosted Add-in by specifying the List path in the format SolutionName/Lists/ListName. Here it is ‘SharePointHostedAddIn/Lists/Employee’.


<Data /> <rows> <row> <fieldname="employee Name">Rajesh</field> <fieldname="employee Address">Kochi,India</field> <fieldname="previous Company">UB Group</field> <fieldname="experience">4</field> </row> <row> <fieldname="employee Name">Jinesh</field> <fieldname="employee Address">Bangalore,India</field> <fieldname="previous Company">IBM</field> <fieldname="experience">12</field> </row> </rows> </data>

We can set the adequate permissions required from the permissions tab of the AppManifest.xml file.

SharePointHostedAddIn

Finally we are all set to publish the app to SharePoint Online. Right Click the solution and click on ‘Publish’.

SharePointHostedAddIn

This will lead us to the publishing page. Click on ‘Package the add-in’.

SharePointHostedAddIn

Visual Studio will do a build and will create the .app package in the local file system.

SharePointHostedAddIn

It will generate the .app file. If we want to analyze the contents we can take a copy of the .app file and rename it to .cab and unzip it.

SharePointHostedAddIn

Now we can upload the .app file to the App catalog. If the catalog is not present, you can refer this article which describes the app catalog creation in SharePoint Online. Once inside the App Catalog, Click on Apps for SharePoint.

http://www.c-sharpcorner.com/article/sharepoint-online-app-catalog-in-office-365/

Click on Upload and select the .app file within the local file system.

http://www.c-sharpcorner.com/article/sharepoint-online-app-catalog-in-office-365/

The upload has been completed. Do a refresh of the page.

http://www.c-sharpcorner.com/article/sharepoint-online-app-catalog-in-office-365/

The SharePoint Hosted add-in has come up in the app catalog.

The SharePoint Hosted add-in has come up in the app catalog.

Now we can add this add-in to the site from the site contents. Doing a simple search from the site contents search box will list out the recently uploaded add-in.

The SharePoint Hosted add-in has come up in the app catalog.

Click on the add-in. It will ask whether to trust it. Click on Trust It.

The SharePoint Hosted add-in has come up in the app catalog.

It will start adding the add-in to the site contents.

The SharePoint Hosted add-in has come up in the app catalog.

Clicking on the add-in will take us to the list which was set as the start page of the add-in. Inside it, we can see the default list items that were set in the elements.xml file.

The SharePoint Hosted add-in has come up in the app catalog.

Summary - Thus we saw how to deploy a SharePoint Hosted Add-in to SharePoint Online in Office 365.