Share via

Threshold issue when Performing CSOM operation on 5000+ Items in a library

Mahadev Prakash Karekar 1 Reputation point
2020-08-11T09:37:24.99+00:00

Hi,
We are performing operation on library having 5000+ documents.I find that any CSOM operation on the List having 5000+ throws the threshold error .How to over come this issue ?

Error: "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator"

I have this code mentioned below

Whenever I try to load below statements for a list having 5001 docs it is throwing threshold error.
Is this a limitation using CSOM ?

cContext.Load(list2.RootFolder.Folders);

Sample code:

string fileUrl = "https://.sharepoint.com/sites/";

            Uri fileUri = new Uri(fileUrl);

            var x = fileUri.Scheme + Uri.SchemeDelimiter + fileUri.Host;

            ClientContext rootContext = new ClientContext(fileUri.Scheme + Uri.SchemeDelimiter + fileUri.Host);

            rootContext.Credentials = BuildCreds();

            Uri webUrl = Web.WebUrlFromPageUrlDirect(rootContext, fileUri);

            ClientContext cContext = new ClientContext(webUrl.ToString());

            cContext.Credentials = BuildCreds();


            cContext.Load(cContext.Web);               

            cContext.ExecuteQuery();

            ListCollection siteLists = cContext.Web.Lists;

            cContext.Load(siteLists);

            cContext.ExecuteQuery();


            foreach (List list2 in siteLists)

            {

                try

                {

                    cContext.Load(list2);

                    cContext.Load(list2.RootFolder);

                    cContext.Load(list2.RootFolder.Folders);

                    cContext.ExecuteQuery();


                }

                catch

                {


                }

            }
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. Baker Kong-MSFT 3,801 Reputation points Moderator
    2020-08-12T02:46:42.397+00:00

    Hi MahadevKarekar-4448,

    This is known issue named Threshold error. Check below doc to get more details:

    If you want to get folders under root folder in a large list, please take a reference of below code:

    More references:

    Best Regards,
    Baker Kong

    Was this answer helpful?


  2. Anupam Shrivastava 176 Reputation points
    2020-08-11T10:41:30.85+00:00

    Yes, SharePoint Online has 5000 items limit for viewing list/library items. You can create indexes on the columns you want to query as explained here and use pagination in your code to extract as explained here.

    Was this answer helpful?

    0 comments No comments

Your answer

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