Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

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;

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

    foreach (SPListItem oListItem in collListItems)
    {
        Response.Write(SPEncode.HtmlEncode(oListItem["Title"].ToString()) +
        "<BR>");
    }

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

Your Answer

 
discard

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.