我知道我可以查看 已安装 已激活 (阅读Kyle所说的内容)网站功能通过SPSite.Features
。
我也知道我可以通过spSite.Features.Add("featureId")
或.Remove
添加或删除功能。
问题是:如何检查某项功能是否有效?在查询SPSite.Features时,我获得了站点的所有功能,它返回SPFeature
个对象。但我仍然不知道该功能是否有效。
基本上我想要一个spSite.Features["featureId"].isActive
或类似的东西。
答案 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