The ListItemCollectionPosition property is used together with the RowLimit property to define paging in a query(to fix server timeout issue while using SPQuery)
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 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. The example also assumes that the list includes a field with the internal name “title” and a field with the internal name “field1”.
Code Sample:
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
SPList oList = oWebsiteRoot.Lists[“Announcements”];// Assuming Site has the list.
SPQuery oQuery = new SPQuery();
oQuery.RowLimit = 10;
oQuery.Query = “<OrderBy Override=\”TRUE\”>” +
“<FieldRef Name=\”FileLeafRef\” /></OrderBy>”;
int index = 1;
do
{
Response.Write(“<BR>Page Index : ” + index + “<BR>”);
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach(SPListItem oListItem in collListItems)
{
Response.Write(SPEncode.HtmlEncode(oListItem[“title”]) + “<BR>”);
}
oQuery.ListItemCollectionPosition =
collListItems.ListItemCollectionPosition;
index ++;
} while(oQuery.ListItemCollectionPosition != null);
}
Data Paging is built into SharePoint’s SPQuery object. It’s a useful feature that you can use to retrieve batches of data instead of retrieving all items of a list.
Advantage: This would help fix issue with server time out while fetching larger amount of data from a List.
————————————–
for queries, suggestions, feedback contact on
email :bipinparshottam@gmail.com
skype: bipin.pankhania