Sometimes a question rises in our mind!
Why only developer site definitions for SharePoint Add-Ins?
There are the cases when we want to enable developer site collection feature when need to side-load an app and deploy directly from Visual Studio. There isn’t a button in the site collection features to let you enable this.
When we are creating a development environment and we want to deploy our apps to our SharePoint website from Visual Studio we shall need to use a Developer site template or another template which has side loading of apps enabled.
Only use side loading of apps for development purposes. So don’t use it on any production environment. To enable side loading of apps for a specific SharePoint website use the following PowerShell script.
On-Premises Environment
Add-PSSnapin Microsoft.SharePoint.PowerShell
Enable-SPFeature e374875e-06b6-11e0-b0fa-57f5dfd72085 –url https://contosotestweb.com
SharePoint Online
As we cannot do above approach with SharePoint Online as Windows PowerShell cmdlets don’t expose the ability to turn features on and off. Now we have seen for Client Side Object Model. Other way is to use SharePoint Client Browser for SharePoint 2010 and 2013. It includes an extremely useful feature to open up PowerShell with the CSOM already loaded.
PowerShell window
we can then easily use the client side object model (CSOM) to enable the developer feature.
$ctx.Load($ctx.Site);
$ctx.ExecuteQuery();
$guid = [System.Guid]”e374875e-06b6-11e0-b0fa-57f5dfd72085″
$ctx.Site.Features.Add($guid,$true,[Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$ctx.ExecuteQuery();
Using an Add-In
You have perform following activities to accomplish this:
- Replace app.js with below code
- Go to the appmanifest for your app and request Manage permission for the site collection.
- Package SharePoint Add-In and then add the .app package to the app catalog for your tenant. Now you can go to any site in your tenancy where you are a site collection administrator and add the app.
- Run SharePoint Add-In
‘use strict’;
var context = SP.ClientContext.get_current();
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function () {
var site = context.get_site();
context.load(site);
context.executeQueryAsync(function () {
site.get_features().add(“e374875e-06b6-11e0-b0fa-57f5dfd72085”, true, 0);
context.executeQueryAsync(function () {
alert(“added the developer site feature to the site collection!”);
},
function(sender, args){
alert(“unable to add the developer site feature to the site collection: ” + args );
});
},
function (sender, args) {
alert(“oops! ” + args);
});
});
Hope you enjoyed reading it.
Please don't forget to Share, Follow and Like to get updated with latest posts.
It gives me motivation to share more knowledge with you.
About Author
Satyendra Mishra
Project Management Professional (PMP) and Microsoft certified, motivated, energetic and accomplished Project Manager / Architect with 15+ years of work experience in Management, Architecture, Analytics, Development and Maintenance. I have been fortunate to be a part of over 25+ .Net / SharePoint projects delivery with various companies across different industry sectors. This has provided me a valuable insight and experience especially in successful implementation of SharePoint based solutions.
My experience in Web application implementation includes technology strategy and road-map definition, business and technical requirements identification, governance, platform architecture, solution design, configuration, development, quality assurance, training, post-production support, team lead and overall project delivery along with project management.
Satyendra Mishra holds a B.Tech. in Computer Science & Engineering and PG Diploma in Advance Computing from Center for Development and Advance Computing, Pune, India. He is also a certified Project Management Professional (PMP).
I love to share Project Management Tips and Tricks by writing Blogs in the Project Management India Community. I have written around 300+ articles in the Project Management, .Net, SharePoint and related client side technologies.