Share via


Sharepoint List Service - GetListItems and Pagination

Ran into this problem and searched high and low for a solution but never found another post detailing the solution.

The issue is that, according to the documentation for GetListItem, located here:

https://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx

Paging should be  done like this:

The GetListItems method supports server-side paging. The XML data returned by this method includes a ListItemCollectionPositionNext attribute inside the rs:Data element that contains the information to support paging. This string contains data for the fields in the sort and for other items needed for paging. You should consider this string internal and not to be modified; modifying it can produce unexpected results. The following example shows the form of this return value when paging is supported.

Xml
 <rs:Data ListItemCollectionPositionNext=" Paged=TRUE&p_ID=100&View=      %7bC68F4A6A%2d9AFD%2d406C%2dB624%2d2CF8D729901E%7d&PageFirstRow=      101" Count=1000 >   <z:row ows_FirstName="Nancy" ows_LastName="Name" ….. />   ...</rs:Data>

To get the next page of data, the queryOption parameter is used, as shown in the following example.

Xml
 <QueryOptions>  <Paging ListItemCollectionPositionNext="     Paged=TRUE&p_ID=100&View=    %7bC68F4A6A%2d9AFD%2d406C%2dB624%2d2CF8D729901E%7d&PageFirstRow=   101" /></QueryOptions>

 

The issue with the above documentation is that when you try to load the above into an XmlElement, then it will fail because the attribute has invalid characters in it.  You can try escaping those characters, however then Sharepoint will not recognize it as a valid pagination token and you wont get proper pagination.

 

 

The trick is to build the XML string with that information blank like this:

 

<QueryOptions>

  <Paging ListItemCollectionPositionNext=”” />

</QueryOptions>

 

Then load it into the XmlElement using the InnerXML, as before.

 

optionsQuery.InnerXml = queryOptions;

 

The go directly to the attributes innertext and set the value:

optionsQuery.ChildNodes[0].Attributes["ListItemCollectionPositionNext"].InnerText = "Paged=TRUE&p_ID=100&View=
    %7bC68F4A6A%2d9AFD%2d406C%2dB624%2d2CF8D729901E%7d&PageFirstRow=101";

Comments

  • Anonymous
    October 14, 2008
    The comment has been removed

  • Anonymous
    November 24, 2008
    All you need to do is XML encode the "&" as queryOptions.InnerXml = "<Paging ListItemCollectionPositionNext="Paged=TRUE&amp;p_Modified=20081021%2022%3a45%3a51&amp;p_ID=9" />";

  • Anonymous
    December 09, 2008
    You shouldn't need to build this pagination query option string manually. You just need to get it from the XmlNode returned by GetListItems and attach it to the queryOptions's innerXml. Please see details at http://ethan-deng.spaces.live.com/blog/cns!1F93FA6E149393C7!118.entry

  • Anonymous
    March 31, 2011
    The XmlNode that is returned from GetListItems has a pointer to the next page ONLY. At one point we were using GetList and GetListItems to create and pupulate an ADO.Net DataTable with the entire List. Once we have the DataTable, we bind it to a GridView control on and ASP.Net web page. We gave the client the ability to Filter, Sort and Update the data. This is a much nicer interface than anything SharePoint has. However, when the List became too large, GetListItems would throw the Soap "System.OutOfMemoryException". We had one of our subs build us a C# Class Library that is basically a wrapper around GetList, GetListItems and UpdateListItems. This Wrapper works in the following manner: When the class is instantiated, the ListURL, ListName, RowsPerPage, Query and ViewFields need to be set. GetSPList will return the first page as an Ado.Net DataTable. It also has the PageNext, PagePrevious and GotoPage(X) methods that return an Ado.Net DataTable. Other read only properties include CurrentPage and TotalPages. If ViewFields, Query or RowsPerPage are reset, it will recalculate TotalPages. GetListItems is another read only property that holds the GetListItems XmlNode. This has worked perfectly for us and solved our problems. They told us this assembly was written in C# and was unit tested using WSS 3.0, MOSS 2007, IE 8.0 and Windows Server 2003 32bit. We purchased only the Assembly. Not the code. If you want, I can put you in touch with these people.

  • Anonymous
    June 27, 2011
    Yeehaaa.. @Yangxin Deng : Thanks Dude. This is what am searching..                    nextPagePointer = "<Paging ListItemCollectionPositionNext='" + listPaginationPointer + "' />";                    nextPagePointer = nextPagePointer.Replace("&", "&");                    ndQueryOptions.InnerXml = nextPagePointer;

  • Anonymous
    September 13, 2011
    Excellent Post. It really solved my issue

  • Anonymous
    November 29, 2011
    hi guys, requesting your quidance.... I have a process that runs on each document on document libraries in multiple site collections. This uses the MOSS web services to fetch data and then run some process on it.. I need to run the process for 100 docs at a time on all document libraries on all Site Collections.. one of the document library has about 1500 docs! The error that I receive if I run on all documents at once is "Error in xml document (1056, 1256)"

  • Anonymous
    November 05, 2012
          The Ecommerce solutions include a website or a web based system, an impressive shopping cart, payment gateway integration, secure and scalable hosting and marketing knowledge. <a href="grouponclone.ideazglobal.com/">groupon script</a>

  • Anonymous
    November 26, 2012
    have a look at my blog for other information on Pagination, www.niteenbadgujar.com/.../sharepoint-client-object-model-caml.html hope that will help others   :)