Enabling The Developer Site Collection Feature SharePoint Online Office 365 -CSOM

In SharePoint 2013, we have a new site template called Developer Site Template. It is a site template, which is used extensively for an app development and you can only deploy apps for SharePoint to a Developer Site.

I have a scenario, where I need to enable the developer Site Collection feature for an existing Site Collection. It may be a team site or publishing site. There isn't a button in Site Collection features to allow you to enable this.

If you were using SharePoint 2013 On-Premises, you’d just run Enable-SPFeature given below.
  1. Enable-SPFeature e374875e-06b6-11e0-b0fa-57f5dfd72085 –url http://gowthamr.sharepoint.com
With SharePoint Online, we can't do this directly, so I have created a simple method to solve this. We can run this script in our Internet Browser console.

We have already seen how to activate the developer site feature, using JSOM. Now, we are going to use CSOM method.
  • FeatureDefinitionScope Enumeration.
  • public enum FeatureDefinitionScope. 
Member name description

None- The feature scope is not specified. The value = 0.

Farm Enumeration, whose values specify that the feature scope has to be at the Farm level. The value = 1.

Site Enumeration, whose values specify that the feature scope has to be at the Site Collection level. The value = 2.

Source code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using Microsoft.SharePoint.Client;  
  6.    
  7. namespace O365SPAddUsertoRole  
  8. {  
  9.     class Program  
  10.     {  
  11.       
  12.       
  13.      private class Configuration  
  14.         {  
  15.                 public static string ServiceSiteUrl = "https:// https://gowthamr.sharepoint.com";  
  16.                 public static string ServiceUserName = "[email protected]";  
  17.                 public static string ServicePassword = "xxxxxxxxxx";  
  18.         }  
  19.   
  20.                  static ClientContext GetonlineContext()  
  21.                           {  
  22.                                     var securePassword = new SecureString();  
  23.                                     foreach (char c in Configuration.ServicePassword)  
  24.                                     {  
  25.                                         securePassword.AppendChar(c);  
  26.                                     }  
  27.                                     var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);  
  28.                                     var context = new ClientContext(Configuration.ServiceSiteUrl);  
  29.                                     context.Credentials = onlineCredentials;  
  30.                                     return context;  
  31.                           }  
  32.   
  33.   
  34.         static void Main(string[] args)  
  35.         {  
  36.             var context=GetonlineContext();  
  37.             Web web = context.Web;   
  38.             var featureId = new Guid("e374875e-06b6-11e0-b0fa-57f5dfd72085");  
  39.             var features = context.Web.Features;  
  40.             features.Add(featureId, true, FeatureDefinitionScope.None);  
  41.             context.ExecuteQuery();  
  42.                  
  43.             
  44.         }  
  45.     }  
  46. }  
Was my blog helpful?

If so, please let us know at the bottom of this page. If not, let me know what was confusing or missing and I’ll use your feedback to double-check the facts, add info and update this blog.
Ebook Download
View all
Learn
View all