You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
Retrieve more items than Threshold limit with CSOM
Summary
This sample shows a ContentIterator implementation that can be used to query large lists as it reads items in batches.
Applies to
Office 365 Multi Tenant (MT)
Office 365 Dedicated (D)
SharePoint 2013 on-premises
Solution
Solution
Author(s)
Core.ListViewThreshold
Anil Lakhagoudar
Version history
Version
Date
Comments
1.0
August 7th 2015
Initial release
Disclaimer
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
Introduction
In SharePoint, when you execute query on Large List, you will receive "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator". To avoid this exception and read list items by batch.
The new Content Iterator class is implemented in CSOM like ContentIterator class which is available in Server Object Model. which can use CSOM to retrieve the items. Also CamlQuery class has been extended with the Methods which can be used to set the CamlQuery properties like SPQuery for Overriding the QueryThrottleMode to avoid the QueryThrottleException.
How to Use?
Using CamlQueryExtension methods
CamlQuerycamlQuery=newCamlQuery();//CamlQuery extension Methods for setting the query properties and query option for Threshold limit//Set View Scope for the QuerycamlQuery.SetViewAttribute(QueryScope.RecursiveAll);//Set Viewfields as String array//camlQuery.SetViewFields(new string[] { "ID", "Title"});//Or Set the ViewFields xmlcamlQuery.SetViewFields(@"<FieldRef Name='ID'/><FieldRef Name='Title'/>");//Override the QueryThrottle Mode for avoiding ListViewThreshold exceptioncamlQuery.SetQueryThrottleMode(QueryThrottleMode.Override);//Set Query conditioncamlQuery.SetQuery("<Eq><FieldRef Name='IndexedField' /><Value Type='Text'>value</Value></Eq>");//If Query has condition Indexed column should be used and set OrderBy with indexed columncamlQuery.SetOrderByIndexField();//Use OrderBy ID field if Query doesn't have condition//camlQuery.SetOrderByIDField();//Set RowLimitcamlQuery.SetQueryRowlimit(5000);
using(ClientContextcontext=newClientContext("SiteUrl")){ContentIteratorcontentIterator=newContentIterator(context);try{contentIterator.ProcessListItem("ListName",camlQuery,ProcessItem,delegate(ListItemitem,System.Exceptionex){returntrue;});catch(Exceptionex){}}//Delegate methodprivatestaticvoidProcessItem(ListItemitem){//Process each item}