
Managing Large Lists
327
Unless the object model override is enabled, the two preceding code snippets have no effect.
If the object model override is disabled, there is a simple way to get around the query limit
by coding around the problem. By making use of the
RowLimit property on the SPQuery and
SPSiteDataQuery objects, you can limit the number of rows returned from the query and avoid
triggering throttling limits.
In addition, you can then page through the entire result set for your query beyond the initial
RowLimit by making use of the ListItemCollectionPosition property. When retrieved from an
SPListItemCollection that was returned from a query, this property indicates the location of the
next set of data in the results set that couldn’t be returned due to the
RowLimit. When set for a query,
this property indicates the position of items in the result set that should be retrieved when the query
executes. This is useful because you can simply pass the
ListItemCollectionPosition from the
results of one query into the call for the next query, until the item is null. The following code demon-
strates how easy it is to page through results using the most common implementation:
using(SPSite site = new SPSite(“http://yoursite”)){
SPList list = site.RootWeb.Lists[“SomeList”];
SPQuery query = new SPQuery();
//set the RowLimit, or page size
Query.RowLimit = 10;
Query.Query = @“<OrderBy><FieldRef ...