Activating SiteCollection Feature




Go back to index

How to activate a site collection feature


Following code block explains how to programmatically activate a site collection scoped feature. You can either give the name or Guid of the feature to be activated.

      using System;
      using SPTool.Library;
      
      namespace SPTool.Test
      {
          class Program
          {
              static void Main(string[] args)
              {
                  SPTSite site = new SPTSite("http://sptool");

                  // Activate site collection scoped feature
                  SPTReturn returnObj = site.ActivateFeature("SPTool.Site.Config", false);

                  // Activate site collection scoped feature using Guid
                  //returnObj = site.ActivateFeature("3FEF8D22-F191-41b6-8F1D-5D50D15BD2A6", false);

                  // Check the status of Activating the feature
                  if (returnObj.State == SPTState.Success)
                  {
                      // Activating Feature Successful
                  }
                  else
                  {
                      // Activating Feature Failed
                  }
              }
          }
      }
      


Go back to index