The code is implemented as follows:
/// <Summary>
/// C #,. net File Download
/// </Summary>
/// <Param name = "URL"> download file address </param>
///
/// <Param name = "Filename"> download address </param>
/// <Param name = "Prog"> display progress bar </param>
///
Public void DownloadFile (string URL, string filename, System. Windows. Forms. ProgressBar prog)
{
Try
{
System. Net. HttpWebRequest Myrq = (System. Net. HttpWebRequest) System. Net. HttpWebRequest. Create (URL );
System. Net. HttpWebResponse myrp = (System. Net. HttpWebResponse) Myrq. GetResponse ();
Long totalBytes = myrp. ContentLength;
If (prog! = Null)
{
Prog. Maximum = (int) totalBytes;
}
System. IO. Stream st = myrp. GetResponseStream ();
System. IO. Stream so = new System. IO. FileStream (filename, System. IO. FileMode. Create );
Long totalDownloadedByte = 0;
Byte [] by = new byte [1024];
Int osize = st. Read (by, 0, (int) by. Length );
While (osize> 0)
{
TotalDownloadedByte = osize + totalDownloadedByte;
System. Windows. Forms. Application. DoEvents ();
So. Write (by, 0, osize );
& Nbs