My friend asked me that he was using web service to fetch data from a list/Document library consisting of 500 items, but the result fetched data only for the first page i.e 100 items.

The list I am querying has pagination, with each page showing 100 items. So, it my list has 500 items, there are 5 pages. But on using the code Lists.GetListItems method, only first 100 records(first page data) is only returned.

The code was as shown below:
Please note: here ibjview is the web reference.

string DocLibName = “Demo Doc Lib”;
XmlNode ndAllView = ibjview.GetViewCollection(DocLibName.Trim());

XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, “Query”, “”);
XmlNode ndViewFields =xmlDoc.CreateNode(XmlNodeType.Element, “ViewFields”, “”);
XmlNode ndQueryOptions = xmlDoc.CreateElement(“QueryOptions”);
ndQueryOptions.InnerXml = “-1”;
ndViewFields.InnerXml = “”;

System.Xml.XmlNode nListView= ibjlists.GetListItems(ndLists.Attributes[“ID”].Value, null, ndQuery, ndViewFields, null, ndQueryOptions, string.Empty);

The xml returned result only for the first page. He was not able to loop the code to get to the next page.
After googling, we found from msdn that,

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.

We debugged, and found the xml was something like:
“<rs:Data ListItemCollectionPositionNext=”
      101″ Count=1000 >
   <z:row ows_FirstName=”Nancy” ows_LastName=”Name” ….. />”

So, we needed to modify the p_ID to go to the next page.
This is how, we modified our code.

XmlNode xmlPosition = nListView.SelectSingleNode(“//@ListItemCollectionPositionNext“);

XmlTextReader reader = new XmlTextReader(nListView.OuterXml, XmlNodeType.Element, null);


reader = new XmlTextReader(nodes.OuterXml, XmlNodeType.Element, null);
XmlDocument xmldoc = new XmlDocument();
 xmldoc.LoadXml(nodes.InnerXml.Replace(“z:”, “”).Replace(“rs:”, “”));
 nodelist1 = xmldoc.SelectNodes(“/data/row”);                                                                                                                                                                                                                                                                                                                          

  for (int i = 0; i < nodelist1.Count; i++)
 { foreach (XmlAttribute attr in nodelist1[i].Attributes) {/*write your code*/}}

  if (xmlPosition != null)
  ndQueryOptions.InnerXml = “<Paging ListItemCollectionPositionNext='” + xmlPosition.InnerXml + “‘ /><MeetingInstanceID>-1</MeetingInstanceID><ViewAttributes Scope=’RecursiveAll’  IncludeRootFolder=’True’ />”;            


The above code will run until xmlposition is null, which will only occur at the last page.