{I+=codeWee;}
[C#] How to download file from web
using System.Net;
...


// [Download File Synchronously]
private void StartDownload(string sURLFileName, string sLocalTargetFilePathName)
{
  WebClient webClient = new WebClient();
  webClient.DownloadFile(sURLFileName, sLocalTargetFilePathName);
}

// [Download File Asynchronously]
private void StartDownloadAsync(string sURLFileName, string sLocalTargetFilePathName)
{
  WebClient webClient = new WebClient();
  webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDonwloadCompleted);
  webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownloadProgress);
  webClient.DownloadFileAsync(new Uri(sURLFileName), sLocalTargetFilePathName);
}

private void OnDownloadProgress(object sender, DownloadProgressChangedEventArgs e)
{
  progressBar.Value = e.ProgressPercentage;
}

private void OnDonwloadCompleted(object sender, AsyncCompletedEventArgs e)
{
  MessageBox.Show("Download completed!");
}
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.