1

我需要在 ManageFeatures.aspx 页面中获取 SPFeatureDefinitions 列表。大概应该是这样的:

...
using (SPWeb web = spSite.OpenWeb())
foreach (var spfeature in SPFarm.Local.FeatureDefinitions)
{
    result.Add(spfeature);                           
}

但是我怎么能确定它spfeature可以被激活web呢?

4

2 回答 2

0

弄清楚了。我必须获取所有功能定义,然后按 Web 范围过滤它们。这是代码:

using (SPSite spSite = new SPSite(siteId))
{
    using (SPWeb web = spSite.OpenWeb(selectedWeb.Id))
    {
        foreach (var spfeature in SPFarm.Local.FeatureDefinitions)
        {
            if (spfeature.Scope.Equals(SPFeatureScope.Web) && !spfeature.Hidden)
            {
                var feature = new Feature();
                feature.Name = spfeature.DisplayName;
                feature.Id = spfeature.Id;
                feature.IsActive = web.Features[spfeature.Id] != null;

                result.Add(feature);
            }                            
        }
    }
}
于 2016-05-17T15:05:22.803 回答
0

尝试使用 if (spfeature.Scope = SPFeatureScope.Web)

于 2016-05-17T15:09:16.300 回答