Microsoft.SharePoint


SPListItemCollectionPosition Class (Microsoft.SharePoint)
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)
Syntax

Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
Public Class SPListItemCollectionPosition
Visual Basic (Usage)
Dim instance As SPListItemCollectionPosition
C#
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public class SPListItemCollectionPosition
Example

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 ( Default Namespace )>Microsoft.SharePoint and ( Default Namespace )>Microsoft.SharePoint.Utilities namespaces.

Visual Basic
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim list As SPList = site.Lists("Announcements")

Dim query As New SPQuery()
query.RowLimit = 10
query.Query = "<OrderBy Override=\"TRUE\">" + 
    "<FieldRef Name=\"FileLeafRef\" /></OrderBy>";


Dim i As Integer = 1

Do

    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").ToString()) & _
            "<BR>")

    Next listItem

    query.ListItemCollectionPosition = _
        listItems.ListItemCollectionPosition

    i += 1

Loop While  Not (query.ListItemCollectionPosition Is Nothing) 
C#
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;

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);
Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPListItemCollectionPosition
Thread Safety

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

Tags :


Community Content

Colby Africa
More Information
Take a look at this blog post for more information if you get stuck:

http://blogs.msdn.com/colbyafrica/archive/2009/02/19/learning-sharepoint-part-vi-list-pagination.aspx

Colby Africa
Tags :

Page view tracker