SPListItemCollectionPosition class

Supports paging through data sets, storing the state that is required to get the next page of data for a specific view of a list.


Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public class SPListItemCollectionPosition

The following code example uses the ListItemCollectionPosition properties of the SPListItemCollection class and the SPQuery class to return an SPListItemCollectionPosition object that stores information about where each page of data ends in the collection of items, and which displays the titles of items in groups of 10 rows. The example assumes that the list is a document library or that folders are enabled in the list.

This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

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

SPQuery oQuery = new SPQuery();
oQuery.RowLimit = 10;
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);

For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.