在 SharePoint 2010 中重新排序列表字段

发布于 2024-12-05 17:32:09 字数 2214 浏览 1 评论 0原文

我正在尝试使用下面的函数重新排序列表字段。但由于某种原因,执行此函数后,当我检查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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-12-12 17:32:09

根据其他示例,我可以找到:

我在代码中看到的唯一区别是,在 ProcessBatchData 调用之前,您没有:

spWeb.AllowUnsafeUpdates = true;

如果添加没有帮助,我建议捕获 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:

spWeb.AllowUnsafeUpdates = true;

If adding that does not help, I would suggest capturing the string output from ProcessBatchData to find out what exactly went wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文