Dropbox API Handling the error when getting metadata for a non-existing path using the Dropbox .NET library


Example

This example uses the Dropbox .NET library to try to get the metadata for an item at a particular path, and checks for a NotFound error:

try {
    var metadata = await this.client.Files.GetMetadataAsync("/non-existant path");
    Console.WriteLine(metadata.Name);
} catch (Dropbox.Api.ApiException<Dropbox.Api.Files.GetMetadataError> e) {

    if (e.ErrorResponse.IsPath) {
        var pathError = e.ErrorResponse.AsPath.Value;
        if (pathError.IsNotFound) {
            Console.WriteLine ("File or folder not found.");
        } else {
            Console.WriteLine (pathError);
        }
    } else {
        Console.WriteLine (e.ErrorResponse);
    }
}