I'm stuck to something probably very basics
So the idea is the following: I have a list with 4 columns : Title, CostCenter, City, currency
Via CSOM, I'd like to read this list, so I did something like that:
ClientContext SPcontext = new ClientContext("MySharepointsite");
Web web = SPcontext.Web;
List list = web.Lists.GetByTitle("ListTest");
CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection items = list.GetItems(query);
SPcontext.Load(list);
SPcontext.Load(items);
SPcontext.ExecuteQuery();
foreach (ListItem listItem in items)
{
Console.Writeline(FieldName = listItem["Title"].ToString());
Console.Writeline(listItem["City"].ToString());
}
But it returns me the following error message:
Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException: 'The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.'
I know that it's comming from my line:
Console.Writeline(listItem["City"].ToString());
because I remove it, it works
Any idea of how could I do that?
Thank you for your help :)