I have some simple code that uses CSOM to read the items in a SharePoint list hosted in SharePoint Online.
List list = ClientContext.Web.Lists.GetById(id);
ClientContext.Load(list,
a => a.ItemCount,
a => a.Title);
ListItemCollection items = list.GetItems( CamlQuery.CreateAllItemsQuery());
ClientContext.Load(items);
ClientContext.ExecuteQuery();
foreach (ListItem li in items)
{
.... // Do some Stuff ...
}
At the end of the ExecuteQuery call I can access the list Title ( "MyList" ) and the record count ( 7 items in total ) but the ListItemsCollection items always has a count of zero.
No errors are thrown.
What do I need to do to actually fetch the list items? Am I missing another call to the CSOM or could their be a permission issue ( wouldn't SharePoint Online tell me if that were the case? )
Help gratefully received!