Downloading Files from WebDAV Server Using .NET API, C#

Using the API you can download either the entire file or request only a part of a file. To download the entire file and save it to local file system:

string license = "<?xml version='1.0' encoding='u...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFile file = session.OpenFile(new Uri("http://server:8080/Products/image.gif"));
file.TimeOut = 36000000; // 10 hours
file.Download("C:\\image.gif");

To download a file and save it directly to the database or any other storage:

IFile file = session.OpenFile("http://server:8080/Products/image.gif");
file.TimeOut = 36000000; // 10 hours
using (Stream webStream = file.GetReadStream())
{
    int bufSize = 1048576; // 1Mb
    byte[] buffer = new byte[bufSize];
    int bytesRead = 0;
    using (FileStream fileStream = File.OpenWrite(file.DisplayName))
    {
        while ((bytesRead = webStream.Read(buffer, 0, bufSize)) > 0)
            fileStream.Write(buffer, 0, bytesRead);
    }
}

The GetReadStream method provides overloaded instances to specify starting byte of the file to download and length. Using this method you can download a single file using several threads at a time or resume broken downloads.