WebFeatures or SiteFeatures property of SPContext.Current can also be used.
Add() and Remove() methods with the GUID as the arguement would do the work. One thing to keep in mind here is that if we try to activate an already activated feature using Add(), an InvalidOperationException is thrown. The only way to check if it is already activated or not is by using indexer and see if an exception is thrown.
SPWeb spCurrentSite = SPContext.Current.Web; spCurrentSite.Features.Add(new GUID("{G__U__I__D}"));(or)
spCurrentSite.Features.Remove(new GUID("{G__U__I__D}"));
In case the GUID is not known, then we would have to chek out for the name in the FeaturesDefinitions collection of the SPFarm Object.
No comments:
Post a Comment