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

%3CLINGO-SUB%20id%3D%22lingo-sub-1582660%22%20slang%3D%22en-US%22%3EThreshold%20issue%20when%20Performing%20operation%20on%205000%2B%20Items%20in%20a%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1582660%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22%22%3EHi%2C%3CBR%20%2F%3E%3CSPAN%3EWe%20are%20performing%20operation%20on%26nbsp%3B%20list%20having%205000%2B%20items.%26nbsp%3B%20i%3C%2FSPAN%3E%3CBR%20%2F%3EI%20find%20that%20any%20CSOM%20operation%20on%20the%20List%20having%205000%2B%20throws%20the%20threshold%20error%20.%3CBR%20%2F%3EI%20have%20this%20code%20mentioned%20below%3CBR%20%2F%3E%3CBR%20%2F%3EWhenever%20I%20try%20to%20load%26nbsp%3B%3C%2FSPAN%3E%26nbsp%3Bbelow%26nbsp%3B%20statements%20for%20a%20list%20having%205001%20docs%20it%20is%20throwing%20threshold%20error.%3C%2FP%3E%3CP%3EIs%20this%20a%20limitation%20using%20CSOM%20%3F%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3EHow%20to%20over%20come%20this%20issue%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EError%3A%20%22%3CSPAN%20class%3D%22%22%3EThe%20attempted%20operation%20is%20prohibited%20because%20it%20exceeds%20the%20list%20view%20threshold%20enforced%20by%20the%20administrator%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EcContext.Load(list2.RootFolder.Folders)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSTRONG%3ESample%20code%3A%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3Bstring%20fileUrl%20%3D%20%22https%3A%2F%2F***.sharepoint.com%2Fsites%2F***%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Uri%20fileUri%20%3D%20new%20Uri(fileUrl)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20var%20x%20%3D%20fileUri.Scheme%20%2B%20Uri.SchemeDelimiter%20%2B%20fileUri.Host%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ClientContext%20rootContext%20%3D%20new%20ClientContext(fileUri.Scheme%20%2B%20Uri.SchemeDelimiter%20%2B%20fileUri.Host)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rootContext.Credentials%20%3D%20BuildCreds()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Uri%20webUrl%20%3D%20Web.WebUrlFromPageUrlDirect(rootContext%2C%20fileUri)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ClientContext%20cContext%20%3D%20new%20ClientContext(webUrl.ToString())%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.Credentials%20%3D%20BuildCreds()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.Load(cContext.Web)%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ListCollection%20siteLists%20%3D%20cContext.Web.Lists%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.Load(siteLists)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20foreach%20(List%20list2%20in%20siteLists)%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20try%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.Load(list2)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.Load(list2.RootFolder)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.Load(list2.RootFolder.Folders)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20cContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20catch%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3CBR%20%2F%3EThanks%26nbsp%3B%3CBR%20%2F%3EMahadev%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1583439%22%20slang%3D%22en-US%22%3ERe%3A%20Threshold%20issue%20when%20Performing%20operation%20on%205000%2B%20Items%20in%20a%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1583439%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F755524%22%20target%3D%22_blank%22%3E%40mkarekar%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EYou%20might%20want%20to%20peek%20a%20little%20within%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FPowershellScripts%2FSPOMod%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethis%3C%2FA%3E%20GitHub%20repository%20of%20%3CA%20href%3D%22https%3A%2F%2Fsocial.technet.microsoft.com%2Fwiki%2Fcontents%2Farticles%2F51763.user-page-arleta-wanat.aspx%23SharePoint_Online%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EArelat%20Wanat%3C%2FA%3E.%3CBR%20%2F%3EAs%20an%20alternative%26nbsp%3Byou%20could%20use%20this%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2FPnP-PowerShell%2Fblob%2Fmaster%2FCommands%2FLists%2FGetListItem.cs%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ecmdlet%3C%2FA%3E%26nbsp%3Bof%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2FPnP-PowerShell%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EPNP%20module%3C%2FA%3E%26nbsp%3Bas%20reference%20instead.%3CBR%20%2F%3EFor%20pagination%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Foffice%2Fsharepoint-csom%2Fee537050(v%3Doffice.15)%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EListItemPosition%3C%2FA%3E%20can%20be%20utilized.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Visitor

Hi,
We are performing operation on  list having 5000+ items.  i
I find that any CSOM operation on the List having 5000+ throws the threshold error .
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 ?  

How to over come this issue ?

 

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

 

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

                    {

 

                    }

                }
Thanks 
Mahadev

1 Reply

@mkarekar 
You might want to peek a little within this GitHub repository of Arelat Wanat.
As an alternative you could use this cmdlet of the PNP module as reference instead.
For pagination the ListItemPosition can be utilized.