开发者

How to check whether a feature has been activated?

I know I can check the installed activated (read what Kyle said below) features of a site via SPSite.Features.

I also know I can add or remove a feature via spSite.Features.Add("featureId") or .Remove.

The question is: How do I check whether a feature is active? When querying SPSite.Features, I get all the features for the site, it returns SPFeature开发者_JS百科 objects. But I still don't know if the feature is active or not.

Basically I would like to have a bool of spSite.Features["featureId"].isActive or something similar.


SPSite.Features doesn't contain installed features. It contains activated features.

To grab a list of all features that are installed, whether activated or not, you need to grab SPFeatureDefinition objects from the SPSite.FeatureDefinitions property.

// Get a list of activated features
SPFeatureCollection features = SPContext.Current.Site.Features;

// Get a list of all feature definitions available
SPFeatureDefinitionCollection featureDefinitions = SPContext.Current.Site.FeatureDefinitions;

A better description from msdn:

The presence of a feature in a collection at the farm 
(Microsoft.SharePoint.Administration.SPWebService), Web application
(Microsoft.SharePoint.Administration.SPWebApplication), site collection
([T:Microsoft.SharePoint.SPSite)], or Web site (Microsoft.SharePoint.SPWeb) 
levels indicates that the feature is activated. Lack of an SPFeature object 
indicates that the object is not active in the given scope.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.featuredefinitions.aspx

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.features.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜