Condividi tramite


SPListItemCollection.ListItemCollectionPosition Property

Gets 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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableAttribute> _
Public ReadOnly Property ListItemCollectionPosition As SPListItemCollectionPosition
    Get
'Usage
Dim instance As SPListItemCollection
Dim value As SPListItemCollectionPosition

value = instance.ListItemCollectionPosition
[ClientCallableAttribute]
public SPListItemCollectionPosition ListItemCollectionPosition { get; }

Property Value

Type: Microsoft.SharePoint.SPListItemCollectionPosition
The paging information.

Remarks

The ListItemCollectionPosition property returns a null reference (Nothing in Visual Basic) if the number of items in the collection is fewer than the row limit for a page.

Examples

The following example is a console application that prints list items in pages with three items per page.

Imports System
Imports Microsoft.SharePoint

Module Test

    Sub Main()
        Using site As SPSite = New SPSite("https://localhost")
            Using web As SPWeb = site.OpenWeb()

                Dim list As SPList = web.GetList("/lists/announcements")

                Dim query As SPQuery = New SPQuery()
                query.RowLimit = 3

                ' Print list items in pages with query.RowLimit items per page.
                Dim index As Integer = 1
                Do
                    Dim items As SPListItemCollection = list.GetItems(query)
                    Console.WriteLine(vbCrLf + "Page: {0}  Items: {1}", index, items.Count)

                    For Each item As SPListItem In items
                        Console.WriteLine(item.Title)
                    Next

                    query.ListItemCollectionPosition = items.ListItemCollectionPosition
                    index = index + 1

                    ' ListItemCollectionPosition is null for the last batch.
                Loop Until query.ListItemCollectionPosition Is Nothing

            End Using
        End Using
        Console.ReadLine()
    End Sub

End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.GetList("/lists/announcements");

                    SPQuery query = new SPQuery();
                    query.RowLimit = 3;

                    // Print list items in pages with query.RowLimit items per page.
                    int index = 1;
                    do
                    {
                        SPListItemCollection items = list.GetItems(query);
                        Console.WriteLine("\nPage: {0}  Items: {1}", index, items.Count);

                        foreach (SPListItem item in items)
                            Console.WriteLine(item.Title);

                        
                        query.ListItemCollectionPosition = items.ListItemCollectionPosition;
                        index++;

                    } // ListItemCollectionPosition is null for the last batch.
                    while (query.ListItemCollectionPosition != null); 
                }
            }
            Console.ReadLine();
        }
    }
}

See Also

Reference

SPListItemCollection Class

SPListItemCollection Members

Microsoft.SharePoint Namespace

ListItemCollectionPosition