如何检查功能是否已激活?

Den*_*s G 5 sharepoint-2010

我知道我可以通过检查已安装的 激活 (阅读Kyle在下面说的内容)功能SPSite.Features.

我也知道我可以通过spSite.Features.Add("featureId")或添加或删除功能.Remove.

问题是:如何检查功能是否有效?查询SPSite.Features时,我获得了站点的所有功能,它返回SPFeature对象.但我仍然不知道该功能是否有效.

基本上我想要一个spSite.Features["featureId"].isActive或类似的bool .

Kyl*_*man 13

SPSite.Features不包含已安装的功能.它包含激活的功能.

要获取已安装的所有功能的列表,无论是否已激活,您都需要SPFeatureDefinitionSPSite.FeatureDefinitions属性中获取对象.

// 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;
Run Code Online (Sandbox Code Playgroud)

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

  • 更正:您需要在禁用功能后处置站点对象,然后显示当前的事务状态. (2认同)