Sharepoint Online CSOM Large Library GetItems exception: The attempted operation is prohibited because it exceeds the list view threshold

Jimmy Tsang 20 Reputation points
2023-08-02T19:01:32.6633333+00:00

I have a library with 100,000+ files, and those files are grouped by folders. So basically each folder has 5000+ files in it.

In a C# console application, when I use CSOM with CamlQuery to get files from any of the folder , I am getting "The attempted operation is prohibited because it exceeds the list view threshold." exception. I am already using ListItemCollectionPosition to get the next page of data. However, if I take out the Where clause from the CamlQuery and do not filter on folder, then the code works perfectly.

Is this a limitation in Sharepoint Online CSOM? If not, then what am I doing wrong and how could I fix this error? Thanks.

User's image

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
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,572 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,441 Reputation points Microsoft External Staff
    2023-08-03T02:44:05.8+00:00

    Hi @Jimmy Tsang,

    We are unable to filter items in caml query when the items over 5000. What we can do is to fetch all the items by camlQuery.ViewXml = "<View Scope='RecursiveAll'><RowLimit>5000</RowLimit></View>"; and filter the data in local by if condition.

    Here is a similar issue with yours, please make a reference

    https://sharepoint.stackexchange.com/questions/216562/caml-query-going-around-the-5000-list-item-threshold


    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.