Why unable to update columns in listitem using CSOM?
-
07-10-2020 - |
Question
I am trying to perform a basic operation,updating a column in a list item of a list.Following is the code ,
List oList = clientContext.Web.Lists.GetByTitle("HomePageTab");
ListItem oListItem = oList.GetItemById(1);
oListItem["Link Location"] = "https://www.google.com";
oListItem.Update();
clientContext.ExecuteQuery();
When i execute this code.I get following error.
{"Column 'Link Location' does not exist. It may have been deleted by another user. /sites/ModusDev/Lists/HomePageTab"}
The issue is the column is available but still unable to update the empty column for the selected listitem.What might be the reason.
I have a url having characters more than 256 which is not accepted when entering in linklocation column. So I am trying to enter the url to link location programatically using CSOM.
La solution
Error reason
oListItem["Link Location"] = "https://www.google.com";
In above code Link Location
is the display name of your column. Use internal name instead.
Update#1
You won't be able to enter 255+ characters using CSOM also.
Autres conseils
You are trying to update a column Link Location
, @Atish is correct that this is a display name. And while you try to update any item you need to refer the internal names.
SharePoint has its own logic of maintaining the internal names. Most often the spaces in the names are converted to _x0020_
. So instead of your code try below.
oListItem["Link_x0020_Location"] = "https://www.google.com";