SharePoint Server 2010 provides a new class named ContentIterator that you
can use to query lists without hitting throttle limits and hence can avoid
receiving an SPQueryThrottleException. You should consider using ContentIterator
if you need to run a query that will return more than 5,000 rows of
data.
The ContentIterator object divides the list items 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.
The following example demonstrates usage of the ContentIterator class.
static int noOfErrors = 0;
static int noOfItemsProcessed = 0;
string camlQuery = @"<View><Query><Where>
<IsNotNull>
<FieldRef Name='Title' />
</IsNotNull>
</Where></Query></View>";
ContentIterator iterator = new ContentIterator();
SPQuery listQuery = new SPQuery();
listQuery.Query = query1;
SPList list = SPContext.Current.Web.Lists["Tasks"];
iterator.ProcessListItems(list,
listQuery,
ProcessItem,
ProcessError
);
}
public bool ProcessError(SPListItem item, Exception e)
{
// process the error
noOfErorrs++;
return true;
}
public void ProcessItem(SPListItem item)
{
noOfItemsProcessed++;
//process the item.
}
http://extreme-sharepoint.com/2012/07/17/data-access-via-caml-queries/
The ContentIterator object divides the list items 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.
The following example demonstrates usage of the ContentIterator class.
static int noOfErrors = 0;
static int noOfItemsProcessed = 0;
string camlQuery = @"<View><Query><Where>
<IsNotNull>
<FieldRef Name='Title' />
</IsNotNull>
</Where></Query></View>";
ContentIterator iterator = new ContentIterator();
SPQuery listQuery = new SPQuery();
listQuery.Query = query1;
SPList list = SPContext.Current.Web.Lists["Tasks"];
iterator.ProcessListItems(list,
listQuery,
ProcessItem,
ProcessError
);
}
public bool ProcessError(SPListItem item, Exception e)
{
// process the error
noOfErorrs++;
return true;
}
public void ProcessItem(SPListItem item)
{
noOfItemsProcessed++;
//process the item.
}
http://extreme-sharepoint.com/2012/07/17/data-access-via-caml-queries/
No comments:
Post a Comment