Activating WebApplication Feature




Go back to index

How to activate a web application feature


Following code block explains how to programmatically activate a web application 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)
              {
                  SPTWebApplication webApplication = new SPTWebApplication("http://sptool/");

                  // Activate web application scoped feature
                  SPTReturn returnObj = webApplication.ActivateFeature("SPTool.Site.Config", false);

                  // Activate web application scoped feature using Guid
                  //returnObj = webApplication.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