Independentsoft
Home
Purchase
Support
Company
Contact
WebDAV .NET
>
Tutorial
> Download with progress
The following example shows you how to report the progress of a download.
C# example
using System; using System.Net; using System.Threading.Tasks; using Independentsoft.Webdav; namespace Sample { class Program { static async Task Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); using (WebdavClient client = new WebdavClient(credential)) { client.BaseAddress = new Uri("https://myserver/dav/"); IProgress<TransferProgress> progress = new Progress<TransferProgress>(p => { Console.WriteLine(p.BytesTransferred + " of " + p.TotalBytes + " bytes (" + p.Percentage?.ToString("0") + "%)"); }); await client.Download("documents/report.pdf", "report.pdf", progress); Console.WriteLine("Download completed."); } } } }
VB example
Imports System Imports System.Net Imports System.Threading.Tasks Imports Independentsoft.Webdav Namespace Sample Module Program Sub Main(args As String()) RunAsync().GetAwaiter().GetResult() End Sub Private Async Function RunAsync() As Task Dim credential As New NetworkCredential("username", "password") Using client As New WebdavClient(credential) client.BaseAddress = New Uri("https://myserver/dav/") Dim progress As IProgress(Of TransferProgress) = New Progress(Of TransferProgress)( Sub(p) Console.WriteLine(p.BytesTransferred & " of " & p.TotalBytes & " bytes (" & p.Percentage?.ToString("0") & "%)")) Await client.Download("documents/report.pdf", "report.pdf", progress) Console.WriteLine("Download completed.") End Using End Function End Module End Namespace
Need help? Ask our developers:
Name*
Email*
Message*