SharePoint, Query & Large Result Set

SharePoint Server 2010 provides a class titled "ContentIterator", We can use it to query on lists with large number of rows.
We should consider using this class if our query returns more than 5000 items. The ContentIterator divides the list into batches and runs the query against one batch of list data at a time. For example


protected void OnContentIterator(object sender, EventArgs args)
{
     SPQuery listQuery = new SPQuery();
     listQuery.Query = "< Query >";
    SPList list = SPContext.Current.Web.Lists["List"];
    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
}

2 comments:

  1. Very informative post. I sometimes do presentations on SharePoint and was wondering if I could use your Print List example in my presentations and refer my audience to your website for further info.

    ReplyDelete