Skip to content

About

Modern async WebDAV client for .NET. Secure file transfers, resumable downloads, locking, and strongly typed APIs for remote storage.

Topics

Resources

Stars

134 stars

Watchers

19 watching

Forks

Repository files navigation

WebDAVClient

Browse WebDAV storage and transfer files from C#/.NET applications. Upload, download, copy, move and delete files without hand-writing DAV requests or parsing XML. Supports .NET 8 and .NET 10.

dotnet add package WebDAVClient

The v3 API, DavClient, is available from NuGet starting with 3.0.0, released October 20, 2026. No local library build is required.

List a folder

Start with an anonymous endpoint:

using System;
using WebDAVClient;
using WebDAVClient.Protocol;
using var client = new DavClient(new Uri("https://dav.example.com/dav/"));
var result = await client.PropFindAsync(DavPath.Root);
result.EnsureSucceeded();
foreach (var resource in result.Resources)
{
    Console.WriteLine(resource.Hrefs[0]);
}

The listing includes the collection itself and its immediate children. See listing and properties for streaming, typed properties and result handling.

Authenticate, list files and download one

Set WEBDAV_ENDPOINT to your HTTPS collection URL, ending in /, and configure WEBDAV_USERNAME and WEBDAV_PASSWORD outside source control. Set WEBDAV_REMOTE_FILE to the name of an existing file in that collection. WEBDAV_OUTPUT optionally selects a new local output path (default download.bin).

Paste this complete program into a console application after installing the package:

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using WebDAVClient;
using WebDAVClient.Helpers;

try
{
    string Required(string name) => Environment.GetEnvironmentVariable(name)
        ?? throw new ArgumentException("Set " + name + ".");

    var endpoint = new Uri(Required("WEBDAV_ENDPOINT"));
    if (endpoint.Scheme != Uri.UriSchemeHttps)
    {
        throw new ArgumentException("Use HTTPS for credentials.");
    }

    using var http = new HttpClient(new HttpClientHandler
    {
        Credentials = new NetworkCredential(
            Required("WEBDAV_USERNAME"), Required("WEBDAV_PASSWORD")),
        UseDefaultCredentials = false,
        AllowAutoRedirect = false,
        AutomaticDecompression = DecompressionMethods.None,
        UseCookies = false
    });
    using var client = new DavClient(endpoint, http);
    using var deadline = new CancellationTokenSource(TimeSpan.FromSeconds(60));

    var listing = await client.PropFindAsync(
        DavPath.Root, cancellationToken: deadline.Token);
    listing.EnsureSucceeded();
    foreach (var resource in listing.Resources)
    {
        Console.WriteLine(resource.Hrefs[0]);
    }

    using var download = await client.DownloadAsync(
        DavPath.FromSegments(Required("WEBDAV_REMOTE_FILE")),
        cancellationToken: deadline.Token);
    download.EnsureHttpSuccess();
    var content = download.Content
        ?? throw new IOException("The server returned no downloadable content.");
    var output = Environment.GetEnvironmentVariable("WEBDAV_OUTPUT") ?? "download.bin";
    await using var file = new FileStream(output, FileMode.CreateNew, FileAccess.Write);
    await content.CopyToAsync(file, deadline.Token);
    Console.WriteLine("Download complete.");
    return 0;
}
catch (WebDAVException ex)
{
    Console.Error.WriteLine($"WebDAV failed: HTTP {ex.ResponseStatusCode ?? ex.GetHttpCode()}.");
    Console.Error.WriteLine("Check the endpoint, credentials, permissions and remote filename.");
    return 1;
}
catch (OperationCanceledException)
{
    Console.Error.WriteLine("The operation timed out or was cancelled.");
    return 130;
}
catch (Exception ex) when (ex is HttpRequestException || ex is IOException || ex is UnauthorizedAccessException
    || ex is ArgumentException || ex is UriFormatException)
{
    Console.Error.WriteLine(ex.Message);
    return 1;
}

The listing includes the collection itself and its immediate children. FileMode.CreateNew prevents overwriting an existing local file; a failed copy can leave a partial file. The getting-started guide explains configuration, errors, partial-file handling and the runnable equivalent. Use an app password, not a bearer token, when your server requires one.

Find the right guide

Task Guide and matching runnable example
Connect to Nextcloud with an app password and read file metadata Nextcloud integration
Connect to ownCloud Server and read file metadata ownCloud integration
Choose anonymous, credentials, Windows or bearer authentication Authentication
List folders, stream large listings and read typed/custom properties Listing and properties
Upload, download and request byte ranges File transfers
Resume interrupted file downloads with validated checkpoints (3.1+) Resumable downloads
Create folders, copy, move and delete safely File management
Acquire, refresh and release a lock; make conditional writes Locking
Request an RFC 6578 change batch Collection synchronization
Diagnose failures, cancellation and resource ownership Errors and lifetimes
Check Nextcloud, ownCloud, IIS, Apache and other servers Server compatibility
Inspect version-specific server evidence or run isolated compatibility tests Independent-server testing
Check supported methods, RFCs and extensions Protocol support
Migrate from Client / IClient or find advanced configuration Detailed API and legacy reference

Nextcloud and ownCloud compatibility is not verified by this project. Implemented protocol features and unit tests are not server compatibility certification. Neither API automatically retries mutations.

Run the examples

Library source is under src, automated tests under tests, and both runnable sample applications under examples.

git clone https://github.com/saguiitay/WebDAVClient.git
Set-Location WebDAVClient
dotnet run --project examples\WebDAVClient.Examples -f net10.0 -- --help

Examples are read-only unless you explicitly enable writes. Each has a guide covering prerequisites, expected results and failure cases. See the documentation index.

Contribute and license

See development and testing and GitHub releases for short changelogs and versioned NuGet links. Detailed historical notes remain in the API reference. WebDAVClient is distributed under MIT. The provenance notice retains attribution for the original kvdb/WebDAVClient.

About

Modern async WebDAV client for .NET. Secure file transfers, resumable downloads, locking, and strongly typed APIs for remote storage.

Topics

Resources

Stars

134 stars

Watchers

19 watching

Forks

Releases

Packages

Used by

Contributors

Languages