在 SharePoint 2010 中重新排序列表字段
我正在尝试使用下面的函数重新排序列表字段。但由于某种原因,执行此函数后,当我检查List Settings
中的字段顺序时,它似乎没有改变。
我得到以下作为 ProcessBatchData
的结果:
<Result ID="0,REORDERFIELDS" Code="-2130575323">
<ErrorText>
Fields have been added or removed since you began this editing session. Please refresh your view and try again
</ErrorText>
</Result>
我在这里缺少什么?
/// <summary>
/// Reorders the share point list fields.
/// </summary>
/// <param name="spWeb">The sp web.</param>
/// <param name="spList">The sp list.</param>
/// <param name="orderedFields">The ordered fields.</param>
private static void ReorderSharePointListFields(SPWeb spWeb, SPList spList, IEnumerable<string> orderedFields)
{
var stringBuilder = new StringBuilder();
using (var xmlTextWriter = new XmlTextWriter(new StringWriter(stringBuilder)))
{
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.WriteStartElement("Fields");
foreach (string orderedField in orderedFields)
{
xmlTextWriter.WriteStartElement("Field");
xmlTextWriter.WriteAttributeString("Name", orderedField);
xmlTextWriter.WriteEndElement();
}
xmlTextWriter.WriteEndElement();
xmlTextWriter.Flush();
const string rpcMethod =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<Method ID=""0,REORDERFIELDS"">
<SetList Scope=""Request"">{0}</SetList>
<SetVar Name=""Cmd"">REORDERFIELDS</SetVar>
<SetVar Name=""ReorderedFields"">{1}</SetVar>
<SetVar Name=""owshiddenversion"">{2}</SetVar>
</Method>";
SPList list = spWeb.Lists[spList.ID];
string rpcCall = string.Format(rpcMethod, list.ID, SPHttpUtility.HtmlEncode(stringBuilder.ToString()),
list.Version);
spWeb.ProcessBatchData(rpcCall);
}
}
I am trying to reorder list fields using the function below. But for some reason, after executing this function, when I go check the field order in the List Settings
, it doesn't seem to have been changed.
I get the following as the result of the ProcessBatchData
:
<Result ID="0,REORDERFIELDS" Code="-2130575323">
<ErrorText>
Fields have been added or removed since you began this editing session. Please refresh your view and try again
</ErrorText>
</Result>
What am I missing here?
/// <summary>
/// Reorders the share point list fields.
/// </summary>
/// <param name="spWeb">The sp web.</param>
/// <param name="spList">The sp list.</param>
/// <param name="orderedFields">The ordered fields.</param>
private static void ReorderSharePointListFields(SPWeb spWeb, SPList spList, IEnumerable<string> orderedFields)
{
var stringBuilder = new StringBuilder();
using (var xmlTextWriter = new XmlTextWriter(new StringWriter(stringBuilder)))
{
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.WriteStartElement("Fields");
foreach (string orderedField in orderedFields)
{
xmlTextWriter.WriteStartElement("Field");
xmlTextWriter.WriteAttributeString("Name", orderedField);
xmlTextWriter.WriteEndElement();
}
xmlTextWriter.WriteEndElement();
xmlTextWriter.Flush();
const string rpcMethod =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<Method ID=""0,REORDERFIELDS"">
<SetList Scope=""Request"">{0}</SetList>
<SetVar Name=""Cmd"">REORDERFIELDS</SetVar>
<SetVar Name=""ReorderedFields"">{1}</SetVar>
<SetVar Name=""owshiddenversion"">{2}</SetVar>
</Method>";
SPList list = spWeb.Lists[spList.ID];
string rpcCall = string.Format(rpcMethod, list.ID, SPHttpUtility.HtmlEncode(stringBuilder.ToString()),
list.Version);
spWeb.ProcessBatchData(rpcCall);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据其他示例,我可以找到:
我在代码中看到的唯一区别是,在
ProcessBatchData
调用之前,您没有:如果添加没有帮助,我建议捕获 ProcessBatchData 的字符串输出,以找出到底出了什么问题。
Based on other examples I can find:
The only difference I saw with your code was that, before your
ProcessBatchData
call, you did not have:If adding that does not help, I would suggest capturing the string output from
ProcessBatchData
to find out what exactly went wrong.