C# SharePoint CSOM:更新多行文本字段

C# SharePoint CSOM: Update multiline text field

我写了一个小的 C# 应用程序来从几个 SP 自定义列表中检索数据。这几个月来一直非常顺利。现在我更新了我的应用程序以更改一些项目。确切地说,我喜欢为某些项目更新一个多行文本字段。这是我的代码:

// Update SharePoint list elements
foreach (var o in toWrite) // List<(int, string)>();
{
    List destList = ctx.Web.Lists.GetByTitle(listToUpdate); // listToUpdate: SP list name
    ListItem listItem = destList.GetItemById(o.Item1); // o.Item1: id to update

    listItem[fieldToUpdate] = o.Item2.ToString(); // o.Item2: new string for plain text multiline field
    listItem.Update();

    ctx.ExecuteQuery();
}

ExecuteQuery() 失败并出现错误“无效请求”。

正在用最大写一个单行文本字段。 255 个字符此方法工作正常,所以我假设对于多行文本字段我需要以某种方式以另一种方式处理这个长字符串。不幸的是,我在 API.

中找不到任何合适的 FieldValue 类

如有任何帮助,我将不胜感激。

更新多行文本字段的详细字符是什么?

我测试了代码片段,它正在更新字段:

        ClientContext ctx = new ClientContext("http://sp/sites/MyDev");
        Web web = ctx.Web;
        ctx.Load(web);
        ctx.ExecuteQuery();
        List list = web.Lists.GetByTitle("MyList");
        ListItem item = list.GetItemById(1);
        item["Note"] = "TestCharacter";
        item.Update();
        ctx.ExecuteQuery();

Jerry_MSFTs 代码和我的一样工作正常。 SharePoint Online 的问题是,当您要更新的自定义字段名为“属性”时,请求将失败。使用另一个名称创建字段后一切正常。