Skip to content
This repository was archived by the owner on Sep 29, 2024. It is now read-only.

WebDavService

Sascha Manns edited this page Sep 6, 2024 · 1 revision

The WebDavService offers the possibility to upload or download files to a WebDavServer.

Instantiation

The service is integrated via dependency injection:

Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((hostingContext, configuration) =>
    {
        configuration.Sources.Clear();
        configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
        IConfigurationRoot configurationRoot = configuration.Build();
        Configuration = configurationRoot;              
	}).ConfigureServices((services) =>
    {
        services.AddSingleton<IConfigurationRoot>(Configuration);
        services.AddHostedService<ConsoleService>(); // This is the main service, who holds all methods we are using.
        services.AddSingleton<IWebDavService, WebDavService>();
    });

Configuration

As a minimum configuration we need the following settings: The respective values ​​are for demo purposes only and must be adjusted.

{
	"wd_password": "Password",
	"wd_subfolder": "Subfolder Path",
	"wd_url": "Webdav Server Url",
	"wd_username": "Username"
}

The "wd_password" is the password for the WebDav server, "wd_subfolder" specifies the path to which the file must be uploaded. The "wd_url" is the URL of the WebDav server. The "wd_username" is the login username.

Call

The following methods can be called:

DownloadFileAsync(string remotefilepath, string localfilepath)

The method downloads a file (remotefilepath) and saves it in the localfilepath.

IMPORTANT: Both paths contain both the path to the file and the file name itself.

DeleteFileAsync(string remotefilepath)

The method deletes a file.

IMPORTANT: The remotefilepath contains the path to the file and also the file name itself.

UploadFileAsync(string localfilepath, string remotefilepath)

The method uploads a file to a WebDav path. IMPORTANT: Both paths include the path to the file as well as the file name itself.

Clone this wiki locally