I'm able to use a console application to connect to a SharePoint Online large list (more than 5,000 items) and retrieve the title. However, even though my CAML query has a row limit, I still get an error when attempting to retrieve list items: "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator."
My CAML syntax is based on this article: Overcoming the List View Threshold in SharePoint CAML queries
How can I successfully retrieve list items?
string siteUrl = "https://test.sharepoint.com/sites/test";
string clientId = "xxxxx-aaaa-aaaa-ffff-gggggggggg";
string clientSecret = "98hg984g3948j49qj";
using (var cc = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))
{
Web oWeb = cc.Web;
List oList = oWeb.Lists.GetByTitle("Test List");
cc.Load(oList, p => p.Title);
cc.ExecuteQuery();
Console.WriteLine(oList.Title);
CamlQuery camlQuery = new CamlQuery();
string viewXML = string.Format(@"<Query><View><RowLimit>10<@"<Query><View><ViewFields><FieldRef Name='ID' /></ViewFields><RowLimit>10</RowLimit></View></Query>");
camlQuery.ViewXml = viewXML;
ListItemCollection collListItems = oList.GetItems(camlQuery);
cc.Load(collListItems);
cc.ExecuteQuery(); //error occurs here
Console.WriteLine("Total Count: " + collListItems.Count);
foreach (ListItem item in collListItems)
{
Console.Write("Description: " + item["Description"]);
Console.Write("Special ID: " + item["Special ID"]);
}
Console.ReadLine();
};