Hai...i have tried below code for provide progressbar option while downloding a file.But in my code
void client_DownloadProgressChange eventprocedure not fired not getting any idea.please solve this.
MY CODE:
public partial class Progressbarwithdownload : Form
{
public Progressbarwithdownload()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri(@"D:\Swathi\modalform\modalform\ASP .NET MVC.pdf"), "D:\\");
button1.Text = "Download In Process";
button1.Enabled = false;
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download Completed");
button1.Text = "Start Download";
button1.Enabled = true;
}
}