Pagination

Certain API operations return lists of objects. When the number of objects in the list is large, the API will paginate the results.

The Files.com DotNet SDK provides multiple ways to paginate through lists of objects.

Creating a list, such as client.Folders.ListFor("/"), sends no request; pages are requested as you load them. Every page comes from the client the list was made with. Lists made with static methods, such as Folder.ListFor("/"), use the default client.

Automatic Pagination

The ListAutoPaging method automatically paginates and loads each page into memory.

Pass a CancellationToken to stop before the next page is loaded. With a token, failures are thrown as they are, such as NotFoundException or OperationCanceledException. Without one, they are wrapped in an AggregateException.

Example Request

using FilesCom.Models;

try
{
    foreach (var file in client.Folders.ListFor("/").ListAutoPaging(cancellationToken))
    {
        Console.WriteLine("- Path: {0}", file.Path);
    }
}
catch (FilesCom.NotAuthenticatedException e)
{
    Console.WriteLine($"Authentication Error Occurred ({e.GetType().Name}): " + e.Message);
}
catch (FilesCom.SdkException e)
{
    Console.WriteLine($"Unknown Error Occurred ({e.GetType().Name}): " + e.Message);
}

Manual Pagination

The LoadNextPageAsync/HasNextPage methods allow for manual pagination and loading of each page into memory.

Example Request

using FilesCom.Models;

try
{
    FilesList<RemoteFile> listing = client.Folders.ListFor("/");
    do
    {
        foreach (var file in await listing.LoadNextPageAsync(cancellationToken))
        {
            Console.WriteLine("- Path: {0}", file.Path);
        }
    } while (listing.HasNextPage);
}
catch (FilesCom.NotAuthenticatedException e)
{
    Console.WriteLine($"Authentication Error Occurred ({e.GetType().Name}): " + e.Message);
}
catch (FilesCom.SdkException e)
{
    Console.WriteLine($"Unknown Error Occurred ({e.GetType().Name}): " + e.Message);
}

Load All Items

The AllAsync method loads all items into memory.

Example Request

using FilesCom.Models;

try
{
    var files = await client.Folders.ListFor("/").AllAsync(cancellationToken);
    foreach (var file in files)
    {
        Console.WriteLine("- Path: {0}", file.Path);
    }
}
catch (FilesCom.NotAuthenticatedException e)
{
    Console.WriteLine($"Authentication Error Occurred ({e.GetType().Name}): " + e.Message);
}
catch (FilesCom.SdkException e)
{
    Console.WriteLine($"Unknown Error Occurred ({e.GetType().Name}): " + e.Message);
}