以编程方式打开网站集功能 SharePoint CSOM



我正在尝试使用 CSOM 在我们的本地环境中以编程方式打开网站集功能。

我不断收到错误: Feature with Id '7201d6a4-a5d3-49a1-8c19-19c4bac6e668' is not installed in this farm, and cannot be added to this scope.

我通过 GUI 检查网站集功能,它就在那里,所以我认为它已打开(它是 OOTB)。

为什么会这样?

法典:

try
          {
            if (featureNode.Attributes != null)
            {
                string guid = featureNode.Attributes["ID"].Value;
                string featureName = featureNode.Attributes["FeatureName"].Value;
                 Guid featureGUID = new Guid(guid);
                 if (isSiteColl)
                 {
                     currentFeatures.Add(featureGUID, false, FeatureDefinitionScope.Site);
                      currentContext.ExecuteQuery();
                  }
                  else
                  {
                      currentFeatures.Add(featureGUID, false, FeatureDefinitionScope.None);
                       currentContext.ExecuteQuery();
                   }
               }
          }

您尝试激活的功能是*元数据导航和过滤',对吧?

问题出在代码的这一部分:

if (isSiteColl)
{
    currentFeatures.Add(featureGUID, false, FeatureDefinitionScope.Site);
    currentContext.ExecuteQuery();
}
else
{
    currentFeatures.Add(featureGUID, false, FeatureDefinitionScope.None);
    currentContext.ExecuteQuery();
}

我不知道isSiteColl的值是什么,因为它没有在您提供的代码中分配。但是对于元数据导航和过滤FeatureDefinitionScope.SiteFeatureDefinitionScope.None都不对。

此枚举指示功能定义的位置,而不是要安装它的位置。正确的值是:

  • Farm OOB 功能和作为自定义服务器场解决方案的一部分安装的功能。
  • Site用于将站点导出为模板时生成的沙盒解决方案和功能。

这是基于我的经验。我一直在努力解决同样的问题,因为这在MSDN上的记录非常少。我不知道什么时候应该使用WebNone值。

最新更新