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.