Sitecore C# - 在同一文件夹中向上/向下移动一个项目

Sitecore C# - move up / down an item in the same folder

标题说明了我的问题的一切

在 sitecore 6.6 上,我必须在一个文件夹中订购项目,我google几天都没有成功。

有人可以帮忙吗?我已经尝试设置 __Sortorder 字段,但我收到一条错误消息,指出 属性 是只读的。

__Sortorder 模板字段有一个 "Read only" 复选框,您可以使用它来允许写入该字段。

您可以使用主菜单中的排序按钮:

  1. Select 项目 move/sort
  2. 打开主菜单
  3. 使用排序部分中的 Up/Down/First/Last 按钮

或键盘快捷键:

  • 向上:(Ctrl+Shift+Alt+向上)
  • 向下:(Ctrl+Shift+Alt+向下)

根据您所写的内容 ("but I get an error saying that the property is readonly"),您在更改 Sort Order 字段值之前尚未开始编辑项目。

最简单的代码是:

item.Editing.BeginEdit();
item[Sitecore.FieldIDs.Sortorder] = "25"; // or any other new value
item.Editing.EndEdit();

Editing.BeginEdit()Editing.EndEdit() 在每个项目更改操作之前和之后都是必需的。

在较旧的 Sitecore 版本中,开发人员过去常常使用 using (new Sitecore.Data.Items.EditContext(item)),但据我所知,不再推荐使用它。

这是一篇关于 Sitecore 项目编辑的示例文章:How to edit an Item in Code Behind