/// <Summary> /// Download file (display progress) /// </Summary> /// <Param name = "url"> </param> /// <Param name = "FILENAME"> </param> /// <Param name = "prog"> </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 (, 0 ,( Int ) By. Length ); While (Osize> 0 ) {Totaldownloadedbyte = Osize + Totaldownloadedbyte; system. Windows. Forms. application. doevents (); so. Write (, 0 , Osize ); If (Prog! = Null ) {Prog. Value = ( Int ) Totaldownloadedbyte;} osize = ST. Read (, 0 ,( Int ) By. Length) ;}so. Close (); ST. Close ();} Catch (System. Exception ){ Throw ;}} /// <Summary> /// Download files /// </Summary> /// <Param name = "url"> </param> /// <Param name = "FILENAME"> </param> Public Void Downloadfile ( String URL, String Filename) {downloadfile (URL, filename, Null );}