SharePoint Pals
 | Sign In
How to Deploy Provider Hosted Apps (Add-Ins) programmatically using CSOM in SharePoint Office 365 by Activating Side Loading Feature
by Sathish Nadarajan 10 Oct 2016
SharePoint MVP
Today  :   31     Total  :    1029

In the recent days, nobody wants to do any manual changes on the site. Almost every customer wants the deployment to be automated, so that it will be easy for them to maintain in future. Considering this, even the APP Development and deployment needs to be automated. There are several ways the APP can be deployed programmatically. Let us have a look of them one by one.

First, as the topic says, let us see how to Deploy APP by Activating the Side Loading Feature.

Before moving on to the Code, let us see what Side Loading is. As per MSDN, the explanation for side loading is as follows.

App side loading, from a SharePoint context, is the ability to install a SharePoint app directly into a site to explicitly bypass the regular governance controls of SharePoint.

i.e., in a Non Developer Site, if we try to deploy the APP programmatically, it will throw an exception. For that, either we need to activate the Developer Feature or loosen the security. Loosen the Security is nothing but, Activating the Side Loading Feature. This, we need to do for fraction of Seconds. i.e., I am activating the Side Loading Feature, Install the APP and immediately de-activate the Side Loading Feature.

Now, let us focus on code. The code is straight forward.

 namespace Console.Office365
     using Microsoft.SharePoint.Client;
     using Newtonsoft.Json.Linq;
     using System;
     using System.Collections.Generic;
     using System.IO;
     class Program
         static void Main(string[] args)
         public static void DeployAPPSideLoading()
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
             string userName = "*********@*****";
             string password = "*******";
             string siteUrl = "https://*******";
             using (var clientContext = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
                 Web web = clientContext.Web;
                 Site site = clientContext.Site;
                 site.ActivateFeature(new Guid("AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D"));
                 string[] appFiles = Directory.GetFiles("D:\\PRACTICE SOURCE CODE\\PNP\\Office365.PHA.OnPrem.APP\\Office365.PHA.OnPrem.APP\\bin\\Debug\\app.publish\\", "*.app"); ;
                 foreach (var appFile in appFiles)
                     var appstream = System.IO.File.OpenRead(appFile);
                     AppInstance app = web.LoadAndInstallApp(appstream);
                 site.DeactivateFeature(new Guid("AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D"));

The very big draw-back in this approach is, as we are bye-passing the regular TRUST approach, the APP will not have permission to make any calls with SharePoint unless, we specifically Trust the APP.

Let me explain in detail. I have added my APP to the Site. In the View Lists, it will be shown as below.


On Click of the APP, I am expecting the Web Title to be displayed on the PHA.

But, while clicking the APP, I will get Access Denied Exception.


To overcome this, we need to manually trust the APP.

1. Go back to View Lists.

2. Click on Permissions.


3. Click on Trust HERE Hyperlink.


4. Now, launch the APP again.

5. We will get the Community Site as Web Title.


This will be very much useful, when we do the Deployments for many sites at a time. Let us see the remaining approaches on the upcoming articles.

Happy Coding,

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter October 23, 22:21
How to Add/Remove User Custom Actions (in Site Actions Menu) Programmatically using CSOM PNP in SharePoint -

Twitter October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation