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

时间:2011-03-02 15:43:04

标签: sharepoint-2010

我知道我可以查看 已安装 已激活 (阅读Kyle所说的内容)网站功能通过SPSite.Features

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

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

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

1 个答案:

答案 0 :(得分:13)

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

要获取已安装的所有功能的列表,无论是否已激活,您需要从SPFeatureDefinition属性中获取SPSite.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;

来自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