You can activate features through code by adding the GUID of the feature to the SPWeb, SPSite, or SPWebApplication object. You can also check if a feature is activated by checking the Features collection for the same GUID value:
Guid g = new Guid(”d2b48bc4-9d29-4090-960c-79c2852cfd65″);
if (web.Features[g] == null) web.Features.Add(g);
To activate features on the Farm level you must add the GUID to the SPWebApplication.WebService object. the SPWebApplication class is in the Microsoft.SharePoint.Administration namespace:
SPWebApplication app = web.Site.WebApplication;
app.WebService.Features.Add(g);
Posted under Developer
This post was written by spotd on April 27, 2009


