Reputation: 341
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!
Upvotes: 0
Views: 1391
Reputation: 1
I had the same problem using Sharepoint 2013 On-Premises and STS as truster broker.
Same behaviour, no errors and I'm getting zero items/documents using CamlQuery.CreateAllItemsQuery() to get a "SELECT ALL" CamlQuery
I solved this creating a new app principal through the page:
/layouts/15/appregnew.aspx
and then assigning enough permissions using the page:
/layouts/15/appinv.aspx
to the HostWeb (not the AppWeb) containing the list. In my case:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Manage"/>
</AppPermissionRequests>
There's still a bug ( Sharepoint bug ) because in this case It's not throwing a "access denied" error
Upvotes: -1
Reputation: 154
Try to use 'include ' to get the data in client context.
ClientContext.Load(list, a.Include(p => p.ItemCount, p => p.Title); ClientContext.ExecuteQuery(); and then check whether item count and title is there or not.
Please let us know whether this list is with in app or not. If it is on the host web then you have to provide read permission under appmanifest.xml->permission tab
Upvotes: 0