Article: Downloading File Asynchronously

Index

Downloading File Asynchronously

You can download a file asynchronously using the HTTP class.

Example

// Create an instance of the HTTP instance
HTTP http = new HTTP();
http.Hostname = “HostnameAddress”;

// Subscribe to the DownloafFileProgressChanged event
http.DownloadFileProgressChanged += new HTTP.DownloadFileProgressChangedDelegate(http_DownloadFileProgressChanged);
 
// Subscribe to the DownloafFileCompleted event
http.DownloadFileCompleted += new HTTP.DownloadFileCompletedDelegate(http_DownloadFileCompleted);
http.DownloadFile(“C:\SaveFiled.txt“);

private void http_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
   Console.WriteLine(“Download completed”);
}
 
private void http_DownloadFileProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
{
   Console.WriteLine(e.BytesReceived.ToString();
}

Related Articles

Main Categories