最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - net framework sharepoint online csom console app crashes when updating more than two items in a list item - Stack Overflow

programmeradmin0浏览0评论

I have a SharePoint list with the following columns Name, Date, Folder

For some reason, whenever I am updating the third column Folder, I get the error Server Exception: Invalid Request.

When I remove the code where it updates this third column, then there is no error.

Why does it keep throwing an error when I am trying to update more than 2 fields for a List Item? Name and Date fields update fine, but every time it gets to Folder field and tries to assign a value to it, the error is thrown. It doesn't matter what type the column is. For simplicity, I just made it a text column and am just assigning a string to it.

List<Dictionary<string, string>> listItems = new List<Dictionary<string, string>>();

foreach (var item in itemResults)
{ 
  CreateFolderInSharepointDocumentLibrary(SP_DOCUMENT_LIBRARY_ROOT, sharePointFolderName);

  Dictionary<string, string> listItemDetails = new Dictionary<string, string>() 
  {
      { LIST_TITLE_KEY, item.Subject },
      { LIST_DATE_KEY, formattedDate },
      { LIST_FILE_KEY, folderUrl }
  };

  listItems.Add(listItemDetails);
}

...
...

foreach (var item in listItems)
{
   CreateListItem(MY_LIST_NAME, item);
}

public void CreateListItem(string listName, Dictionary<string, string> item)
{
    using (var clientContext = GetSharePointClientContext())
    {
      Web web = clientContext.Web;

      clientContext.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id));
      clientContext.Load(web, a => a.ServerRelativeUrl);
      clientContext.ExecuteQuery();

      List targetList = clientContext.Web.Lists.GetByTitle(listName);
      ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
      ListItem oListItem = targetList.AddItem(itemCreateInfo);

 
      oListItem["Name"] = "Test One";
      oListItem["Date"] = "Test Two";
      oListItem["Folder"] = "Test Three"; // --> Error always here. No error when removing

      oListItem.Update();
      clientContext.ExecuteQuery();
    }
}

When ever it gets to here oListItem["Folder"] = "Test Three"; it keeps crashing and throwing the error. When I uncomment, program runs fine.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论