This documentation is archived and is not being maintained.

SPQuery.RowLimit Property

Windows SharePoint Services 3

Gets or sets a limit for the number of items returned in the query per page.

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

'Declaration
Public Property RowLimit As UInteger
	Get
	Set
'Usage
Dim instance As SPQuery
Dim value As UInteger

value = instance.RowLimit

instance.RowLimit = value

Property Value

Type: System.UInt32
An unsigned 32-bit integer that specifies the row limit.

The RowLimit property is used together with the ListItemCollectionPosition properties of the SPListItemCollection and SPQuery classes and with the SPListItemCollectionPosition class 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 RowLimit property contains a value that corresponds to the value of the RowLimit element in Collaborative Application Markup Language.

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.

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
Try
    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

    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")) + _
              "<BR>"))
        Next listItem

        query.ListItemCollectionPosition = _
          listItems.ListItemCollectionPosition
        i += 1
    Loop While Not (query.ListItemCollectionPosition Is Nothing)
Finally
    webSite.Dispose()
End Try

The next code example uses the RowLimit property to specify a limit of 50 items per page to return in the query.

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

Dim webSite As SPWeb = SPContext.Current.Site.AllWebs["Site_Name"]
Try
    Dim list As SPList = webSite.Lists("List_Name")

    Dim query As New SPQuery()
    query.ViewFields = "<FieldRef Name='Field1'/>" + _
        "<FieldRef Name='Field2'/>"
    query.RowLimit = 50
    Dim items As SPListItemCollection = list.GetItems(query)

    Dim item As SPListItem
    For Each item In  items
        Response.Write((SPEncode.HtmlEncode(item.Xml) + "<BR>"))
    Next item
Finally
    webSite.Dispose()
End Try
NoteNote

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Show: