Download A List Of files
Code:
Imports System.Net
Public Class Form1
Private WithEvents HttpClient As WebClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
ListBox2.Items.Add(TextBox2.Text)
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
SaveFileDialog1.ShowDialog()
TextBox2.Text = SaveFileDialog1.FileName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim theResponse As HttpWebResponse
Dim theRequest As HttpWebRequest
Dim length As Long
Try
HttpClient = New WebClient
Dim total As Integer = ListBox1.Items.Count
Dim current As Integer = -1
While current < total
ListBox1.SelectedIndex = current + 1
ListBox2.SelectedIndex = current + 1
Dim down As String = ListBox1.SelectedItem
Dim add As String = ListBox2.SelectedItem
theRequest = WebRequest.Create(Me.ListBox1.SelectedItem)
theResponse = theRequest.GetResponse
length = theResponse.ContentLength
Label5.Text = "Length = " & (length / 1024) & "Bytes"
HttpClient.DownloadFileAsync(New Uri(down), add)
' Label3.Text = HttpClient.DownloadFile((down), add)
Label3.Text = "Current Status : Downloading"
Do While HttpClient.IsBusy
Application.DoEvents()
Loop
current = current + 1
End While
Catch ex As Exception
'ListBox1.Items.Clear()
'ListBox2.Items.Clear()
End Try
'Checks if the file exist
' theRequest = WebRequest.Create(Me.ListBox1.SelectedItem)
' theResponse = theRequest.GetResponse
' Dim length As Long = theResponse.ContentLength
'Label5.Text = "Length = " & length
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
HttpClient.CancelAsync()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
HttpClient.CancelAsync()
Me.Close()
End Sub
Private Sub HttpClient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles HttpClient.DownloadProgressChanged
ProgressBar1.Maximum = e.TotalBytesToReceive
ProgressBar1.Value = e.BytesReceived
Label4.Text = "Downloaded" & e.ProgressPercentage
If e.ProgressPercentage = 100 Then
Label3.Text = "download complete"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Label6.Text = "Downloaded " & Me.ProgressBar1.Value & "%"
End Sub
End Class
Code:
Imports System.Net
Public Class Form1
Private WithEvents HttpClient As WebClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
ListBox2.Items.Add(TextBox2.Text)
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
SaveFileDialog1.ShowDialog()
TextBox2.Text = SaveFileDialog1.FileName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim theResponse As HttpWebResponse
Dim theRequest As HttpWebRequest
Dim length As Long
Try
HttpClient = New WebClient
Dim total As Integer = ListBox1.Items.Count
Dim current As Integer = -1
While current < total
ListBox1.SelectedIndex = current + 1
ListBox2.SelectedIndex = current + 1
Dim down As String = ListBox1.SelectedItem
Dim add As String = ListBox2.SelectedItem
theRequest = WebRequest.Create(Me.ListBox1.SelectedItem)
theResponse = theRequest.GetResponse
length = theResponse.ContentLength
Label5.Text = "Length = " & (length / 1024) & "Bytes"
HttpClient.DownloadFileAsync(New Uri(down), add)
' Label3.Text = HttpClient.DownloadFile((down), add)
Label3.Text = "Current Status : Downloading"
Do While HttpClient.IsBusy
Application.DoEvents()
Loop
current = current + 1
End While
Catch ex As Exception
'ListBox1.Items.Clear()
'ListBox2.Items.Clear()
End Try
'Checks if the file exist
' theRequest = WebRequest.Create(Me.ListBox1.SelectedItem)
' theResponse = theRequest.GetResponse
' Dim length As Long = theResponse.ContentLength
'Label5.Text = "Length = " & length
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
HttpClient.CancelAsync()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
HttpClient.CancelAsync()
Me.Close()
End Sub
Private Sub HttpClient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles HttpClient.DownloadProgressChanged
ProgressBar1.Maximum = e.TotalBytesToReceive
ProgressBar1.Value = e.BytesReceived
Label4.Text = "Downloaded" & e.ProgressPercentage
If e.ProgressPercentage = 100 Then
Label3.Text = "download complete"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Label6.Text = "Downloaded " & Me.ProgressBar1.Value & "%"
End Sub
End Class
No comments:
Post a Comment