首页 > 解决方案 > C# SharePoint CSOM:更新多行文本字段

问题描述

我编写了一个小 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 类。

我将不胜感激任何帮助。

标签: c#sharepointcsom

解决方案


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

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

        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();

在此处输入图像描述


推荐阅读