Screenshot
Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
#REGION Windows Form Designer The code ///
/// summary> private () {this.label1 = new system.windows.forms.Label (); this.label2 = new system.windows.forms.label (); this.txturi = new system. Windows.Forms.TextBox (); this.txtPath = new System.Windows.Forms.TextBox (); this.folderBD = new System.Windows.Forms.FolderBrowserDialog (); this.btnSelect = new System.Windows.Forms.Button (); This.btndownload = new system.windows.Forms.Button (); this.stbar = new system.windows.Forms.statusbar (); this.suspendlayout (); // // label1 // this.label1. Location = new system.drawing.point (8, 24); this.label1.name = "label1"; this.label1.size = new system.drawing.size (96, 23); this.label1.tabindex = 0; This.Label1.Text = "Download file URI:"; /// Label2 // this.label2.location = new system.drawing.point (16, 64); this.label2.name = "label2"; this .label2.Size = new System.Drawing.Size (88, 23); this.label2.TabIndex = 1; this.label2.Text = "local save path:"; // // txtURI // this. TXTURI.LOCATION = New System.drawing.Point (112, 25); this.txturi.Name = "txturi"; this.txturi.size = new system.drawing.size (208, 21); this.txturi.tabindex = 2; this.txturi.text = ""; /// TXTPATH // this.txtPath.Location = new system.drawing.point (112, 65); this.txtPath.name = "txtpath"; this.txtpath. Size = new system.drawing.size (208, 21); this.txtpath.tabindex = 3; this.txtpath.text = ""; /// btnselect // this.btnselect.location = new system.drawing.point (328, 64); this.btnselect.name = "btnselect";
THIS.BTNSELECT.TABINDEX = 4; this.btnselect.text = "Select Path ..."; this.btnselect.click = new system.eventhandler (this.btnselect_click); // // btndownload // this.btndownload. Location = new System.Drawing.Point (112, 104); this.btnDownLoad.Name = "btnDownLoad"; this.btnDownLoad.TabIndex = 5; this.btnDownLoad.Text = "Download"; this.btnDownLoad.Click = new System.eventhandler (this.btndownload_click); /// stbar // this.stbar.location = new system.drawing.point (0, 184); this.stbar.name = "stbar"; this.stbar.size = New system.drawing.size (424, 22); this.stbar.tabindex = 6; // // Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system. Drawing.size (424, 206); this.controls.add (this.stbar); this.Controls.add (this.btndownload); this.Controls.add (this.btnselect); this.Controls.Add (this. TXTPATH; this.Controls.add (this.txturi); this.controls.add (this.label2); this.controls.add (this.label1); this.name = "Form1"; this.text = "form1"; this.ResumeLayout (false);} #ENDREGION
///
Private void btnselect_click (Object sender, system.eventargs e) {if (folderbd.showdialog () == DialogResult.cancel) {return;} txtpath.text = folderbd.selectedPath;}
private void btnDownLoad_Click (object sender, System.EventArgs e) {// Open threads, to improve the user experience Thread th = new Thread (new ThreadStart (StartDownLoad));. //th.Name="New DownLoad "; th.Start ();} private void startDownLoad () {string url = string.Empty; string fileName = string.Empty; int n = 0; string path = string.Empty; btnDownLoad.Enabled = false; url = txtURI.Text; n = Url.lastIndexOf ('/'); filename = url.substring (n 1); path = txtpath.text "//" filename;
Try {WebRequest Request = WebRequest.create (URL);} catch (WebException EX) {MessageBox.show (ex.Message, "Error");
Try {stbar.text = "Start downloading files ..."; Client.downloadfile (URL, PATH); STBAR.TEXT = "Download, files have been saved" path.tostring ();} catch (WebException EX) {MessageBox.show (EXMESSAGE, "Error"); stbar.text = string.empty;} finally {btndownload.enabled = true;}}}} XMP>