Click here to Skip to main content
15,919,500 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Right this is what i have so far, basically everything works fine now.
But there is one thing that is wrong which is weird not sure why its doing it but it works after it starts downloading the second part.

How it works:
You click the button and it then runs the 'Background worker' which then checks if the webhost is online then activates the 'download sub' which reads the lines of each links that's within the '.txt' that it finds in the 'DIR'.

Whilst it downloads it shows the files it's downloading ,size of the file, bytes rev, percentage of the download.
But only starts this when it starts on the second link in the '.txt' but still downloads the first of course.


//////////Example//////////////////////////

VB
Imports System.IO
Imports System.Text
Imports System.Net

'#Form#
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
End Sub

'#Button Click#
Private Sub GetFile_Button(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

BackgroundWorker1.RunWorkerAsync()
End Sub

'#Download Sub#
Private Sub DownloadTest3()
Dim AppPath As String
AppPath = Environment.CurrentDirectory()

For Each line In IO.File.ReadAllLines(AppPath + "\CheckFiles.txt")
Fulldownload = New WebClient
Fulldownload.DownloadFileAsync(New Uri(line), (AppPath.TrimEnd("\"c) & GetFileNameFromURL(line)))
Next
End Sub

'#Function#
Private Function GetFileNameFromURL(ByVal URL As String) As String
If URL.IndexOf("/"c) = -1 Then Return String.Empty

Return "\" & URL.Substring(URL.LastIndexOf("/"c) + 1)
End Function

'#DownloadProgressChangedEvents#
Private Sub Fulldownload_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles Fulldownload.DownloadProgressChanged

ProgressBar1.Value = e.ProgressPercentage
Me.lolsize.Text = "FileSize: [" & e.TotalBytesToReceive & "]KB"
Me.lolgetdata.Text = "Downloaded: [" & e.BytesReceived & "]KB"
Me.lolpercent.Text = e.ProgressPercentage & "%"
End Sub

Public Sub FullDownloadComplete(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles Fulldownload.DownloadProgressChanged

If ProgressBar1.Value = 100 Then
ProgressBar1.Value = 0
Me.lolsize.Text = "FileSize: [ ]KB"
Me.lolgetdata.Text = "Downloaded: [ ]KB"
Me.lolpercent.Text = " %"
End If
End Sub

'#And for last the Backgroundworker#    
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Dim AppPath As String
AppPath = Environment.CurrentDirectory()

ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
Dim Full As String = ("http://**/files/")
Dim theResponse As HttpWebResponse
Dim theRequest As HttpWebRequest
Try
theRequest = WebRequest.Create(Full)
theResponse = theRequest.GetResponse
DownloadTest3()

Catch ex As Exception
MsgBox("It's offline dumbass")
End Try
End Sub
Posted
Comments
Syngravez 10-Mar-13 9:32am    
Anyone ? O.o , out of loads of people knowing VB.net on this site they can't fix this at all ?
bbirajdar 10-Mar-13 12:34pm    
There are atleast 25000 people online at any moment on codeproject. If you do not get answers, then it only means that the question is not clear. Instead of challenging somebody, try to read the question as a third person and check if it can be understood by a person who does not know anything about your project. Try to be technical as much as possible. because technology is the only thing common between your project and us to understand your problem...

Personally , I did not understand your question....

"But there is one thing that is wrong which is weird not sure why its doing it but it works after it starts downloading the second part." ... What second part ?

"You click the button and it then runs the 'Background worker' which then checks if the webhost is online then activates the 'download sub' which reads the lines of each links that's within the '.txt' that it finds in the 'DIR'." ...... What is "..and it then runs "? , What is ..'download sub'? Where is the .txt and what does it contain ? links to what ? and what is DIR ?


[no name] 10-Mar-13 13:04pm    
This is the answer as far as I am concerned. The question is vague and could not be answered in it's present form. Virtual 5.
Syngravez 10-Mar-13 13:14pm    
Well i put the question bluntly as possible. I don't know how to put it more clearly then this.
Shall i post the source and clear this up a bit then ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900