SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I need to store say 10,000 items in a list, but want to call them sequentially 2000 items at a time, what is the best method for doing that? I assume it's similar to a paged call, but want to execute this the right way.

This is in SharePoint 2007

share|improve this question
up vote 3 down vote accepted

You can use the built-in SPQuery paging mechanism

SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["Announcements"];

SPQuery oQuery = new SPQuery();
oQuery.RowLimit = 2000;
oQuery.Query = "<OrderBy Override=\"TRUE\">" + 
    "<FieldRef Name=\"FileLeafRef\" /></OrderBy>";

int intIndex = 1;

    Response.Write("<BR>Page: " + intIndex + "<BR>");
    SPListItemCollection collListItems = oList.GetItems(oQuery);

    foreach (SPListItem oListItem in collListItems)
        Response.Write(SPEncode.HtmlEncode(oListItem["Title"].ToString()) +

    oQuery.ListItemCollectionPosition =
} while (oQuery.ListItemCollectionPosition != null);
share|improve this answer
You sir, are a gentleman and a scholar. – Wesley Apr 25 '12 at 17:47
Nope, I just know how to Google :) – Rob Windsor Apr 25 '12 at 17:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.