Skip to content

Asynchronous cross-platform WebDAV client for .NET Standard 1.1+

License

Notifications You must be signed in to change notification settings

tipstrade/WebDavClient

 
 

Repository files navigation

WebDAV .NET client Build status

Asynchronous cross-platform WebDAV client for .NET Standard 1.1+. It aims to have a full support of RFC4918.

Installation

Install WebDav.Client via NuGet.

Install-Package WebDav.Client

Supported platforms

  • .NET Framework 4.5+
  • .NET Core
  • Mono
  • Xamarin
  • UWP

For more information see .NET Standard.

Usage examples

Basic usage:

using (var webDavClient = new WebDavClient())
{
    var result = await webDavClient.Propfind("http://mywebdav/1.txt");
    if (result.IsSuccessful)
        // continue ...
    else
        // handle an error
}

Using BaseAddress:

var clientParams = new WebDavClientParams { BaseAddress = new Uri("http://mywebdav/") };
using (var webDavClient = new WebDavClient(clientParams))
{
    await webDavClient.Propfind("1.txt");
}

Operations with files and directories (resources & collections):

var clientParams = new WebDavClientParams { BaseAddress = new Uri("http://mywebdav/") };
using (var webDavClient = new WebDavClient(clientParams))
{
    await webDavClient.Mkcol("mydir"); // create a directory

    await webDavClient.Copy("source.txt", "dest.txt"); // copy a file

    await webDavClient.Move("source.txt", "dest.txt"); // move a file

    await webDavClient.Delete("file.txt", "dest.txt"); // delete a file

    await webDavClient.GetRawFile("file.txt"); // get a file without processing from the server

    await webDavClient.GetProcessedFile("file.txt"); // get a file that can be processed by the server

    await webDavClient.PutFile("file.xml", File.OpenRead("file.xml"), "text/xml"); // upload a resource
}

PROPFIND example:

// list files & subdirectories in 'mydir'
var result = await webDavClient.Propfind("http://mywebdav/mydir");
if (result.IsSuccessful)
{
    foreach (var res in result.Resources)
    {
        Trace.WriteLine("Name: " + res.DisplayName);
        Trace.WriteLine("Is directory: " + res.IsCollection);
        // other params
    }
}

Authentication example:

var clientParams = new WebDavClientParams
{
    BaseAddress = new Uri("http://mywebdav/"),
    Credentials = new NetworkCredential("user", "12345")
};
using (var webDavClient = new WebDavClient(clientParams))
{
    // call webdav methods...
}

Synchronous API:

  // will block the current thread, so use it cautiously
  var result = webDavClient.Propfind("1.txt").Result;

License

WebDAVClient is licensed under the MIT License. See LICENSE.txt for more details.

About

Asynchronous cross-platform WebDAV client for .NET Standard 1.1+

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.6%
  • Other 0.4%