Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Reading all items from a Large List
In SharePoint 2010, when you execute SPQuery on Large List, you get exception "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 we can use Content Iterator.
To use ContentIterator include Microsoft.Office.Server.dll available in 14/ISAPI/ and include namespace Microsoft.Office.Server.Utilities.
Advantages
- Fetches list items as a batch, load is reduced.
- If indexed column condition return more value than List View Threshold, it handles by batch. Normal SPQuery fails in this condition.
- We can stop batch processing any time.
Disadvantage
- You cannot include Non-Indexed column in SPQuery condition.
//Run as console application
My large list contains 74,006 items, as we can see from output, that it reads 74,006 items in batches of 2000 items.
Output
Reading items in Large List with SPQuery where condition
Ensure that the following conditions have been met.
- Only Indexed fields can be used.
- You should include ContentIterator.ItemEnumerationOrderByNVPField.
- You cannot combine Non-Indexed column with Indexed column / use them directly.
In SPQuery, if indexed field fetches more than List View Threshold limit, it will fail. The ContentIterator handles it by batch processing.
**Output:
**
Only 25157 Items had the digit ‘9’ in the SynchId field.
Note: Avoid using CAML Builder for querying Large Lists, it might get hanged.