Why Developer Site definition for SharePoint Add-Ins

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:

  1. Replace app.js with below code
  2. Go to the appmanifest for your app and request Manage permission for the site collection.
  3. 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.
  4. 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);

});

});

Like & Share…

Satyendra Mishra




Leave a Reply

Your email address will not be published. Required fields are marked *