Upgrading Your Server Implementation to WebDAV Server Engine .NET v7

IT Hit WebDAV Server Engine v7 provides methods for requesting a specified range of items when listing folder content and searching. You can also specify specify sort conditions when listing folder content.

Interfaces Changes

The IItemCollectionAsync.GetChildrenAsync() method and  now provide new parameters for specifying number of items to skip before returning the the rest of the items (offset) and a number of items to return (page size). The GetChildrenAsync() function also provides a parameter to pass sorting conditions (sort columns). It also has a different return type: PageResults class which contains items that correspond to the requested range and sorting and a total number of items in a folder.

Upgrading Your Code

To upgrade your server follow these steps:

  1. Update the ITHit.WebDAV.Server package. Reference a new packages from NuGet or from IT Hit WebDAV Server Engine for .NET SDK install folder (by default C:\Program Files (x86)\IT Hit\WebDAV Server Engine\<version>\Server\bin\).

    After upgrade your server DAV header will advertise paging support:

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

    Now the WebDAV Ajax Library v5.8 or later can detect paging support. You can use the WebDAV Ajax Library to make paging requests and build paging UI. See Implementing Paging Through Folder Children Items and Search Results article for more details.

  2. Update your GetChildrenAsync() method. Replace your GetChildrenAsync() method:

    public virtual async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(
        IList<PropertyName> propNames)
    {
        IList<IHierarchyItemAsync> children = new List<IHierarchyItemAsync>();
        ...
        return children;
    }

    with a new method:

    public virtual async Task<PageResults> GetChildrenAsync(
        IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
    {
        IList<IHierarchyItemAsync> page = new List<IHierarchyItemAsync>();
        // Populate your page list here according to offset, nResults and orderProps.
        ...
    
        // Get total number of items in the folder.
        long totalItems = ...
    
        return new PageResults(page, totalItems);
    }

    You need to add 3 new parameters and change the return type.

    See how to implement paging in the Implementing Paging Through Folder Children Items and Search Results article.

    Note that if you do not need the paging support you can just ignore new parameters and leave your existing implementation. The only change you need to make is to modify the return object to be PageResults type. Pass list of items that you previously were returning from GetChildren to PageResults constructor:

    IList<IHierarchyItemAsync> children = new List<IHierarchyItemAsync>();
    // Populate your children list here.
    ... return new PageResults(children, children.Count);
  3. Update your SearchAsync() method. Replace SearchAsync() method:

    Task<IEnumerable<IHierarchyItemAsync>> SearchAsync(
        string searchString, SearchOptions options, List<PropertyName> propNames)
    {
        IList<IHierarchyItemAsync> searchResults = new List<IHierarchyItemAsync>();
        ...
        return searchResults;
    }

    with:

    public async Task<PageResults> SearchAsync(
        string searchString, SearchOptions options, List<PropertyName> propNames, long? offset, long? nResults)
    {
        IList<IHierarchyItemAsync> searchResultsPage = new List<IHierarchyItemAsync>();
        // Populate search results page according to offset and nResults.
        ...
    
        // Get total number of items in search results.
        long totalItemsFound = ...
    
        return new PageResults(searchResultsPage, totalItemsFound);
    }

    You need to add 2 new parameters and change the return type. As with GetChildrenAsync() method, if you do not need paging, you can ignore new parameters and pass the list of search results and total number of items in results directly to PageResults object constructor:

    IList<IHierarchyItemAsync> searchResults = new List<IHierarchyItemAsync>();
    ...
    return new PageResults(searchResults, searchResults.Count);
    

 

See Also: