Share via

SPQuery.ListItemCollectionPosition property

Gets or sets an object that is used to obtain the next set of rows in a paged view of a list.

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


Public Property ListItemCollectionPosition As SPListItemCollectionPosition
Dim instance As SPQuery
Dim value As SPListItemCollectionPosition

value = instance.ListItemCollectionPosition

instance.ListItemCollectionPosition = value
public SPListItemCollectionPosition ListItemCollectionPosition { get; set; }

Property value

Type: Microsoft.SharePoint.SPListItemCollectionPosition
An SPListItemCollectionPosition object.


The ListItemCollectionPosition property is used together with the RowLimit property to define paging in a query. Specifically, the SPListItemCollectionPosition object is used to iterate through all the items in a collection n items at a time, where n is the value specified as a row limit.


The following code example uses the ListItemCollectionPosition properties of the SPListItemCollection and SPQuery classes to return an SPListItemCollectionPosition object for storing where each page of data ends in the collection of items and 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. The example also assumes that the list includes a field with the internal name “Field1” and a field with the internal name “Field2”.


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.

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

Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
    Dim list As SPList = webSite.Lists("Announcements")
    Dim query As New SPQuery()
    query.RowLimit = 10    
    query.Query = "<OrderBy Override=\"TRUE\">" & _
       "<FieldRef Name=\"FileLeafRef\" /></OrderBy>";
    Dim i As Integer = 1

        Response.Write(("<BR>Page: " + i + "<BR>"))
        Dim listItems As SPListItemCollection = list.GetItems(query)

        Dim listItem As SPListItem
        For Each listItem In  listItems
            Response.Write((SPEncode.HtmlEncode(listItem("Title")) & "<BR>"))
        Next listItem

        query.ListItemCollectionPosition = _
        i += 1
    Loop While Not (query.ListItemCollectionPosition Is Nothing)
End Try
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
    SPList oList = oWebsiteRoot.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"]) + 
        oQuery.ListItemCollectionPosition = 
    } while(oQuery.ListItemCollectionPosition != null);

See also


SPQuery class

SPQuery members

Microsoft.SharePoint namespace