If somebody like the post and its helpful in your work then, add comments.

Wednesday, April 15, 2009

Pagination using SharePoint 2007 Web Service API

When you're using the list web service method GetListItems and the result is limited by RowCount (either because you
specified it in the request or due to it being in the view that's used) then the rs:data element will contain both
ItemCount and ListItemCollectionPositionNext attributes like this:

... all the z:row elements

When you want the next page you need to use the same query as before but with the ListItemCollectionPositionNext
attribute in a Paging element in QueryOptions like this:

GetListItems takes a lot of parameters:
public XmlNode GetListItems (string listName, string viewName, XmlNode query, XmlNode viewFields, string rowLimit,
XmlNode queryOptions, string webID)

To start using paging you need a rowLimit. This can be given by specifying a view which has a row limit, but it's better
to specify your paging size in the rowLimit parameter (it's a string like "25").

When you specify a rowLimit then you first request will only return that number of rows, but have the
ListItemCollectionPositionNext in rs:data for use in the request for the next page.

The Code:
ListWebRef.Lists SPSCustomerList = new Lists();
SPSCustomerList.Url = strSiteURL;
SPSCustomerList.Credentials = System.Net.CredentialCache.DefaultCredentials;
string strListID = SPSCustomerList.GetList([ListName]).Attributes["ID"].Value;

//XML DOcumnets object
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");//Query
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");//Views fields
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");//Options
ndViewFields.InnerXml = "";

XmlNode XMLCustomerList = SPSCustomerList.GetListItems(strListID, null, ndQuery, ndViewFields, "200", ndQueryOptions, null);

XmlNode XMLPositon = XMLCustomerList.SelectSingleNode("//@ListItemCollectionPositionNext");

// set next page info if there is more page
ndQueryOptions.InnerXml = ""; XmlNode XMLCustomerList2 = SPSCustomerList.GetListItems(strListID, null, ndQuery, ndViewFields, "200", ndQueryOptions, null);


  1. Check out my blog.


  2. Hi Bharat,

    I tried the above solution, but it won't work for me. I am getting "The type or namespace name 'ListWebRef' could not be found" error. Could you please share the complete code.

    Thanks in Advance.

  3. ListWebref is the WebService reference in the code, add that and your namespace will resolve