We should use ContentIterator class if we need to run a query that will return more than 5,000 rows of data. Essentially, the ContentIterator instance divides the list into chunks and runs the query against one chunk of list data at a time. Each list item is processed asynchronously by a callback method until the query is complete.
protected void OnTestContentIterator(object sender, EventArgs args)
{
SPQuery listQuery = new SPQuery();
listQuery.Query = “[CAML query goes here]”;
SPList list = SPContext.Current.Web.Lists[“MyList”];
ContentIterator iterator = new ContentIterator();
iterator.ProcessListItems(list,
listQuery,
ProcessItem,
ProcessError);
}
public bool ProcessError(SPListItem item, Exception e)
{
// Process the error
return true;
}
public void ProcessItem(SPListItem item)
{
// Process the item
}