如何以编程方式还原 Sitecore 项目桶?

How to Revert Sitecore Item Bucket Programatically?

当我通过登录到 sitecore 手动恢复项目桶时,它按预期工作。但是,当通过下面的代码时,会出现意想不到的短语 'There are hidden items in this containder',并且当通过启用存储桶复选框查看时,不存在子项。

Sitecore.Buckets.Managers.BucketManager.Unbucket(项目);

按照Unbucket按钮的反汇编代码,不仅有Unbucket(item)调用:

BucketManager.UnBucketItem(contextItem);
foreach (Item current in from item in contextItem.GetChildren(ChildListOptions.SkipSorting)
where item.TemplateID.ToString() == Constants.BucketFolder
select item)
{
  ItemManager.DeleteItem(current);
}

它首先取消存储项目,然后遍历留下的存储桶文件夹并将它们删除。