2011-03-02 256 views
5

我知道我可以檢查 安裝 激活通過SPSite.Features(讀什麼凱爾下面說的)網站的功能。如何檢查功能是否已被激活?

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

現在的問題是:如何檢查功能是否爲有效?當查詢SPSite.Features時,我得到了該網站的所有功能,它返回SPFeature對象。但我仍然不知道該功能是否處於活動狀態。

基本上我想有一個spSite.Features["featureId"].isActive布爾或類似的布爾。

+0

檢查此鏈接。希望它對您有所幫助http://www.directsharepoint.com/2011/04/programmatically-check-feature-is.html – 2011-04-10 20:05:09

回答

12

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

要獲取已安裝的所有功能的列表,無論是否激活,您都需要從SPSite.FeatureDefinitions屬性中獲取SPFeatureDefinition對象。

// 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

+0

完美的解釋 - 奇怪的是,在Powershell SPSite.Features中,即使在我通過前端禁用了它... – 2011-03-02 21:23:41

+2

更正:您需要在禁用某個功能後處理站點對象,然後顯示當前的事件狀態。 – 2011-03-03 09:35:11

相關問題