Wednesday, August 24, 2011

SharePoint GetListItems Paging

Has anyone messed with this?

Paging, Ordering and Filtering using SharePoint Lists Web Service GetListItems.
We started receiving the Soap System.OutOfMemoryException when using SharePoint Lists Web Service GetListItems to pull back 20,000 list items in our ASP.Net web app.

We needed a way of paging the data using SharePoint Lists Web Services. We wanted to retrieve 1 page at a time from the SharePoint List. We also needed to navigate to the next page, previous page and directly to a page. We also needed to know the total number of pages.


The GetListItems web service function has a rowLimit parameter, which indicates the number of list items per page. Using this parameter, the web service would retrieve only the first page of data. Not the entire list.

However, how would we navigate to the next page, the previous page or a specific page?
The Silver Bullet has arrived.
We developed a C# Public Sealed Utility Class that is a wrapper around the SharePoint Lists Web Service functions for GetList, GetListItems and UpdateListItems.

This wrapper retrieves data from GetListItems one page at a time. The data can be retrieved as an Ado.Net DataTable or the same XmlNode that is returned from the GetListItems function.

The key feature of this wrapper is the ability to navigate to the next page, previous page and directly to a page.

Custom public functions such as PageNext, PagePrevious and PageGoto(X) return a specidic page of data as an Ado.Net DataTable.
Custom public functions such as PageNextNode, PagePreviousNode and PageGotoNode(X) return the same XmlNode that GetListItems returns.
There is also a read only attribute that indicates the total number of pages.

The assembly can be copied to the bin folder of your app and works in the following manner:
When the class is instantiated, the client must set the ListURL, ListName, RowsPerPage, Query, ViewFields and QueryOptions.

ListURL and ListName are mandatory.
RowsPerPage, Query, ViewFields and QueryOptions can be null.

Username and Password are set only properties. If these are left blank, then default credentials will be used.

The public function GetSPList will return the first page of data as an Ado.Net DataTable. GetSPListNode is the same, but returns the GetListItems XmlNode.

At this point, PageCount has been established.

After this, the PageNext, PagePrevious and PageGoto(X) functions can be used.

The property values for ViewFields, Query, RowsPerPage or QueryOptions can be updated. The next call to GetSPList or GetSPListNode will recalculate PageCount and return the first page of data.
Other public functions include ListItemsModify and ListItemsDelete.
This has worked perfectly for us and solved our problems.

This assembly is developed for SharePoint Lists. We did not develop this for Document Libraries. It is written is C# using Visual Studio 2008 SP1. It was unit tested using a C# Visual Studio 2008 Asp.Net Web App. The platform is WSS 3.0, MOSS 2007, IE 8.0 and Windows Server 2003 32bit.

Both the assembly and code are for sale.
Both assembly and code come with the C# web app we used for testing that displays all the different features.

Thank You,

Bill Fote
fotew@yahoo.com

1 comment: