0% found this document useful (0 votes)
77 views2 pages

FRM Download

This C# code defines a Windows Form that allows a user to download a file from a URL. It uses a WebClient object to asynchronously download the file. Progress bars are updated during the download process using DownloadProgressChanged and DownloadFileCompleted events. When the download finishes, a message box is displayed to notify the user if it completed successfully or reported an error.

Uploaded by

santhosh1212
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

FRM Download

This C# code defines a Windows Form that allows a user to download a file from a URL. It uses a WebClient object to asynchronously download the file. Progress bars are updated during the download process using DownloadProgressChanged and DownloadFileCompleted events. When the download finishes, a message box is displayed to notify the user if it completed successfully or reported an error.

Uploaded by

santhosh1212
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ProcessBar

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace frmDownolad
{
public partial class Form1 : Form
{
WebClient cl;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
Uri url = new Uri(textBox1.Text);
progressBar1.Value = 0;
cl.DownloadFileAsync(url, "localfile.html");//after downloaded it
will store localfile.html in bin folder

private void Form1_Load(object sender, EventArgs e)


{
cl = new WebClient();
cl.DownloadFileCompleted += new AsyncCompletedEventHandler(f1);
cl.DownloadProgressChanged += new
DownloadProgressChangedEventHandler(f2);
}

void f2(object sender, DownloadProgressChangedEventArgs e)


{
progressBar1.Value = e.ProgressPercentage;
}

void f1(object sender, AsyncCompletedEventArgs e)


{
if (e.Error == null)
MessageBox.Show("Downloaded");
else
MessageBox.Show(e.Error.Message);
}

}
}

You might also like