SharePoint Online - List View Threshold Limit

Alexander P 21 Reputation points
2024-09-18T14:46:24.83+00:00

I am encountering problems with a SharePoint CSOM query.

I am using paging in a query agains a large SharePoint online list.

Here is my code:

Uri uri = new Uri(web.Context.Url);
string baseUrl = uri.GetLeftPart(UriPartial.Authority);
CamlQuery query = new CamlQuery();
query.ViewXml = "<View Scope='RecursiveAll'><RowLimit Paged='TRUE'>" + _rowLimit.ToString() + "</RowLimit><ViewFields><FieldRef Name="FileRef" /></ViewFields><Query><Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'>" + changeDate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value></Geq></Where></Query></View>";
do
{
  // Get the files matching the query
  ListItemCollection items = list.GetItems(query);
  web.Context.Load(items);
  web.Context.ExecuteQuery();
  Console.WriteLine($"Found {items.Count} files that may contain macros in document library");
  // Output the results
  foreach (ListItem item in items)
  {
  allFiles.AppendLine(baseUrl + location); }
  //Reset the current pagination info
  query.ListItemCollectionPosition = items.ListItemCollectionPosition;
} while (query.ListItemCollectionPosition != null);

SharePoint online always return a problem with the threashold!

If I skip the query, then everything is OK, but I need to filter the files by myself.

Is this bug known or did I miss something?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,007 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 46,811 Reputation points Microsoft Vendor
    2024-09-19T03:05:28.5766667+00:00

    We are unable to fetch list items more than threshold limit. For example: you have 10,000 items, there are 3000 item which meets your caml expression.

    At first you need to fetch all the items 10,000 and keep it in collection object, then query this collection object using Linq expression.

    Please refer to below codes:

    var web = clientContext.Web;
                var list = web.Lists.GetByTitle("listName");
                clientContext.Load(list);
                clientContext.ExecuteQuery();
                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View Scope='RecursiveAll'><RowLimit>5000</RowLimit></View>";
                List<ListItem> items = new List<ListItem>();
                do
                {
                    ListItemCollection listItemCollection = list.GetItems(camlQuery);
                    clientContext.Load(listItemCollection);
                    clientContext.ExecuteQuery();
                    //Adding the current set of ListItems in our single buffer
                    items.AddRange(listItemCollection);
                    //Reset the current pagination info
                    camlQuery.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition;
                } while (camlQuery.ListItemCollectionPosition != null);
    			
                var filteritems = items.Where(tt =>(tt.FieldValues["Column_A"] != null) &&
                (tt.FieldValues["Column_B"] != null) &&
                (tt.FieldValues["Column_C"] == "") 
               );
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.