asp.net winform download file and show download progress bar tutorial

Source: Internet
Author: User
Tags zip

WinForm download file and display download progress sample

The code is as follows Copy Code

<summary>
Show progress
</summary>
<param name= "Val" ></param>
private void Progressbar_value (int val)
{
progressBar1.Value = val;
Label1. Text = val. ToString () + "%";
}

<summary>
Download files
</summary>
<param name= "url" ></param>
<param name= "SaveFile" ></param>
<param name= "DownloadProgressChanged" ></param>
<param name= "downloadfilecompleted" ></param>
private void DownloadFile (string url, string savefile, action<int> downloadprogresschanged, Action downloadfilecompleted)
{
WebClient client = new WebClient ();
if (downloadprogresschanged!= null)
{
Client. DownloadProgressChanged + = Delegate (object sender, DownloadProgressChangedEventArgs e)
{
This. Invoke (downloadprogresschanged, e.progresspercentage);
};
}
if (downloadfilecompleted!= null)
{
Client. downloadfilecompleted + = Delegate (object sender, AsyncCompletedEventArgs e)
{
This. Invoke (downloadfilecompleted);
};
}
Client. DownloadFileAsync (new Uri (URL), savefile);
}
delegate void Action (); . NET Framework 2.0 Custom Delegate action

///<summary>
///Click to download
///</summary>
///<param name= "sender" ></PARAM>
///& Lt;param name= "E" ></param>
private void Button1_Click (object sender, EventArgs e)
{
  & nbsp DownloadFile ("Http://www.111cn.net/update.zip", @ "F:update.zip", progressbar_value, NULL);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.