I am trying to use an AppOnlyAuthenticated context in order to loop over all the documents in a specific list in Sharepoint. The reason to use the AppContext is that this needs to be automated (part of a script) and using an actual user accounts seems like the wrong choice.
Repro:
// using OfficeDevPnp.Core;
// using Microsoft.SharePoint.Client;
var webUrl = "https://company.sharepoint.com/sites/test";
var appId = "xXXXX-xxxx-.....";
var appSecret = "longSecret";
var listTitle = "ListTitle";
var am = new AuthenticationManager();
using (var context = am.GetAppOnlyAuthenticatedContext(webUrl, appId, appSecret))
{
var lists = context.Web.Lists;
var list = lists.GetByTitle(listTitle);
var listItems = list.GetItems(CamlQuery.CreateAllItemsQuery(rowLimit = 5));
context.Load(lists);
context.Load(list);
context.Load(listItems, items => item.Include(i => i.Id));
context.ExecuteQuery();
var list_ItemCount = list.ItemCount;
var listItems_Count = listItems.Count;
}
}
The list_ItemCount has the correct value of items in that list of files but listItems_Count is zero. Obviously, when trying to loop over listItems, there is nothing to enumerate.
Could it be a permission thing? Or is something else causing the issue?