function | download
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Net;
Using System.IO;
Using System.Text;
private void Button3_Click (object sender, System.EventArgs e)
{
String Downloadurl=textbox3.text;
String Localpath=textbox4.text;
if (Downfile (Downloadurl,localpath))
{
MessageBox.Show ("Download Complete");
}
Else
{
MessageBox.Show ("Error occurred during download:");
}
}
public bool Downfile (string url,string localpath)
{
Try
{
Uri u = new uri (URL);
HttpWebRequest mrequest = (HttpWebRequest) webrequest.create (U);
Mrequest.method = "Get";
Mrequest.contenttype = "application/x-www-form-urlencoded";
HttpWebResponse WR = (HttpWebResponse) mrequest.getresponse ();
Stream sIn = wr. GetResponseStream ();
FileStream fs = new FileStream (LocalPath, FileMode.Create, FileAccess.Write);
Long length = wr. ContentLength;
Long i = 0;
Decimal j=0;
while (I < length)
{
byte[] buffer = new byte[1024];
i + + sin.read (buffer, 0, buffer. Length);
Fs. Write (buffer, 0, buffer.) Length);
if ((i% 1024) ==0)
{
J=math.round (Convert.todecimal (convert.todouble (i)/convert.todouble (length)) *100), 4);
statusbar1.text= "Current download File size:" +length. ToString () + "byte current download size:" +i+ "byte Download Progress" +j.tostring () + "%";
}
Else
{
statusbar1.text= "Current download File size:" +length. ToString () + "byte current download size:" +i+ "bytes";
}
}
Sin.close ();
Url Close ();
Fs. Close ();
return true;
}
catch {return false;}
}