A blog about SharePoint, Project Server and other Microsoft technologies.

Thursday, May 16, 2013

SharePoint - Iterate through large list

Retrieving list items from SharePoint list from code is the most basic thing, and every SharePoint developer is familiar with it.This is the easiest way for retrieving items of a SharePoint list from code:

returns all items of a list at once. If your list has large amount of items (for example, more then 2000), then this can be a serious performance issue.If you have extremely large list, like 1 000 000 items, this code will certainly crash your server.The solution is to using SPQuery class and its RowLimit property like this:

With SPQuery, execution is faster. This query returns all fields from a list, but you can make it even faster if you define only the fields that you need, and not all of them. RowLimit property of SPQuery class ensures that only specific number of items will be processed in one iteration.