Paging Through Folder Children Items

The paging support is available in IT Hit WebDAV Server Engine for .NET v7.0 Beta and later versions.

The WebDAV Server Engine for .NET provides support for paging through the children items and sorting results. The client application can requesting a specified range of items with a specified sort conditions.

Detecting Paging Support

To determine server features the client application submits OPTIONS request to folder item. The WebDAV Server Engine v7.0 and later will always add 'paging' token to the DAV header to indicate paging support:

DAV: 1,2,3,resumable-upload,paging

Implementing Paging

The IItemCollectionAsync.GetChildrenAsync() method provides parameters for specifying number of items to skip before returning the the rest of items, number of items to return and sort columns list. Below you can see a sample GetChildrenAsync() method implementation for file system storage:

public virtual async Task<PageResults> GetChildrenAsync(
    IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
    IList<IHierarchyItemAsync> children = new List<IHierarchyItemAsync>();

    FileSystemInfo[] fileInfos = dirInfo.GetFileSystemInfos();
    long totalItems = fileInfos.Length;

    // Apply sorting.
    fileInfos = SortChildren(fileInfos, orderProps);

    // Apply paging.
    if (offset.HasValue && nResults.HasValue)
        fileInfos = fileInfos.Skip((int)offset.Value).Take((int)nResults.Value).ToArray();

    foreach (FileSystemInfo fileInfo in fileInfos)
        string childPath = Path + EncodeUtil.EncodeUrlPart(fileInfo.Name);
        if (fileInfo is DirectoryInfo)
             children.Add(new DavFolder((DirectoryInfo)fileInfo, context, childPath + "/"));
             children.Add(new DavFile((FileInfo)fileInfo, context, childPath));

    return new PageResults(children, totalItems);

 Here is the description of each parameter :

  • offset - number of items to skip before returning the rest of the items.
  • nResults - number of items to return (page size). Note that on the last page the number of items may be smaller than specified in this parameter.
  • orderProps - list of sort order columns. You will sort your result set according to these rules before applying paging.

The GetChildrenAsync() function returns the PageResults class instance that contains list of items that corresponds to the requested page as well as a total number of items in the folder. Typically you will use the total number of items on the client side to calculate the number of pages available and to render pages links/buttons UI.

The total number of items is optional and can be null, as soon as in some systems determining a total number of items could consume resources or is not required.

In the Paging Through Children Items article you can find how to submit a paging request and implement paging using WebDAV Ajax Library.

Note that paging is an IT Hit WebDAV Server Engine specific feature and is not supported by most WebDAV Clients such as Windows Explorer/Mini re-director and Mac OS X Finder. They always request all items in the folder and offset, nResults and orderProps parameters will always be null when used with these clients.