如何使用 Sharepoint Server 对象模型获取场中所有可以为特定 Web 激活的已停用功能?
How to get all of the deactivated Features in the farm that could be activated for the specific web using Sharepoint Server Object Model?
我需要像 ManageFeatures.aspx 页面中那样获取 SPFeatureDefinitions 列表。大概应该是这样的:
...
using (SPWeb web = spSite.OpenWeb())
foreach (var spfeature in SPFarm.Local.FeatureDefinitions)
{
result.Add(spfeature);
}
但是我如何确定 spfeature
可以在 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);
}
}
}
}
尝试使用 if (spfeature.Scope = SPFeatureScope.Web)
我需要像 ManageFeatures.aspx 页面中那样获取 SPFeatureDefinitions 列表。大概应该是这样的:
...
using (SPWeb web = spSite.OpenWeb())
foreach (var spfeature in SPFarm.Local.FeatureDefinitions)
{
result.Add(spfeature);
}
但是我如何确定 spfeature
可以在 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);
}
}
}
}
尝试使用 if (spfeature.Scope = SPFeatureScope.Web)