I'm trying to update a SharePoint list via C# So first I check if my item already exists, if it is, I add his id in my lUpdate variable. So my code works, it goes in the loop (for the update and the insert), it takes each values well but for the update, it doesn't update my list (my values stay the same in the list) but the insert works
Here find my code:
public static void SetSharePointitem()
{
ClientContext clientContext = new ClientContext("SharePointSite");
List oList = clientContext.Web.Lists.GetByTitle("MyList");
if (lUpdate!=null)
{
ListItem oListItem = oList.GetItemById(lUpdate);
foreach (var item in projectCenter)
{
oListItem[item.FieldNameTarget] = item.FieldValue;
oListItem.Update();
}
clientContext.ExecuteQuery();
}
else
{
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
foreach (var item in projectCenter)
{
oListItem[item.FieldNameTarget] = item.FieldValue;
oListItem.Update();
}
clientContext.ExecuteQuery();
}
}
Any idea of what I'm doing wrong? When I reach the clientContext.ExecuteQuery(); in my first loop, I get an error message which says:
item does not exist
Thanks for your help