I've downloaded your code and modified a bit in order to learn something new. I am really new to VB.NET. Now i've constated, that if I delete some parts of the code to let the downloader start automatically, an error occurs and says, that the access to the path was denied.
How is this possible? I am admin on my computer...
The codes i have deleted are, where you have to choose the path, the file URL and the download button. instead of theese functions i have defined some constants: 1) FileURL, 2)DownloadPath. The rest should start automatically, when the program is loaded.
The issue with your code is you are not specifying a full file name to download the file to. You are specifying a full URL, but only a directory to download to. You need to specify a directory AND filename to save the downloaded file as.
The access denied error is a bit cryptic, but that is what it means. The code is trying to open a file to write the downloaded data to, but you basically tell it to try to write the data to the folder itself, not a file in the folder.
Just use path.combine to fix this:
Code:
Private Sub updater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
_Downloader = New WebFileDownloader
'GET FULL FILE PATH/NAME FROM EXE PATH AND FROM URL FILE NAME
Dim DownloadedFileName As String = IO.Path.Combine(Application.StartupPath(), IO.Path.GetFileName(launcher))
_Downloader.DownloadFileWithProgress(launcher, DownloadedFileName)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
End Sub
I'm guessing you did change some values in here before you uploaded it to protect some info right?
yeah I only have changed the link, because it is a file, i don't want that everybody reads...
Originally Posted by kleinma
The issue with your code is you are not specifying a full file name to download the file to. You are specifying a full URL, but only a directory to download to. You need to specify a directory AND filename to save the downloaded file as.
The access denied error is a bit cryptic, but that is what it means. The code is trying to open a file to write the downloaded data to, but you basically tell it to try to write the data to the folder itself, not a file in the folder.
Just use path.combine to fix this:
Code:
Private Sub updater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
_Downloader = New WebFileDownloader
'GET FULL FILE PATH/NAME FROM EXE PATH AND FROM URL FILE NAME
Dim DownloadedFileName As String = IO.Path.Combine(Application.StartupPath(), IO.Path.GetFileName(launcher))
_Downloader.DownloadFileWithProgress(launcher, DownloadedFileName)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
End Sub
wooow yeah... you are right! OMG it's logic... how stupid i am. thank you very very much.
But it just doesn't seem to return a true speed, i measured it with DU meter and anything past about 300 kb/s seems to go amiss, this calculation is being made on the whole download, not just the chunk, when i tried the same on just a chunk stopping and resetting the stopwatch each loop, it drastically slowed down the download
I also added a counter so that the calculation isn't made on every loop so that the output is still legible to humans (Only updates every 100 loops) but as above, it still slowed the download,
Any further direction or suggestions would be great
Last edited by ph4nt0m; Jun 3rd, 2009 at 04:09 PM.
hello thanks for this code..it was very usefull
quick question.. i just want to add webbrowser on this form and if i click the download links on webbrowser it is possible to automatically put the links on txtUrl?
I would imagine it would involve handling the navigating event of the browser control and checking the e.url property to see if the type of file being navigated to is one that should be downloaded. Unfortunatly this is probably something that needs to be manually coded to check for extensions (like exe, zip, etc...)
Then once you determine it is a file download, you set e.cancel to true in the navigating event to cancel the browser from doing the download, and you take the e.url property and use that to download using the progress bar downloader class from this thread.
The browser does have a filedownload event, but it does not give you any event arguments to cancel it, so I don't see how it would be useful for this scenario.
How to get download speed?
there is e function that count downloaded byte. and i know the 1byte = 8 bit. but how do i make the program to count the byte downloaded every second?
i have open 2 downloader forms. why cant they download a file each at the same time? why do the other wait for the first to finish? and if i opens 3 forms and tired it, then my program stops working.
How to get download speed?
there is e function that count downloaded byte. and i know the 1byte = 8 bit. but how do i make the program to count the byte downloaded every second?
i have open 2 downloader forms. why cant they download a file each at the same time? why do the other wait for the first to finish? and if i opens 3 forms and tired it, then my program stops working.
well.. that don´nt work for me. i get like "0" or "0 byte" in the label i have to show the speed.
i dont understand how that would work because lastSize and cSize has no value. you just tell the program the they are going to have the same value.. over and over again. right?
how can i make the downloader rdy for files more than 7GB i has a file over more than 8GB but it gives me an error with this downloader what must i change in code
I don't know why people love to post something like "it gives me an error" without providing a single detail about the error, yet they expect us to know exactly how to fix the issue.
I don't know why people love to post something like "it gives me an error" without providing a single detail about the error, yet they expect us to know exactly how to fix the issue.
The Problem is the ProgBar.Maximum he gives only a integer but i need Int64 for files over 1GB
You just need to use some math to scale down the progress bar values to something acceptible to fall within the bounds of a 32 bit integer since that is what the progress bar takes for its values.
You just need to use some math to scale down the progress bar values to something acceptible to fall within the bounds of a 32 bit integer since that is what the progress bar takes for its values.
Dim maximum_value As Long = (maximum value)
Dim current_value As Long = (current value)
While maximum_value > Integer.MaxValue
current_value \= 2
maximum_value \= 2
End While
Me.ProgressBar1.Maximum = CInt(maximum_value)
Me.ProgressBar1.Value = CInt(current_value)
kleinma is it possible to add the code to some sort of bgworker so that the app doesn't kinda hang every time the dl size gets updated? i have no idea how backgroundworkers work actually but have been told some stuff(they keep the app from going not responding).
kleinma how can I change this application to be able to download files >54K. The app. is working for my smaller files but on the larger files I receive an error message at statment
Dim myWebResponse As WebResponse = wRemote.GetResponse
msg- an error occured durning download; a devise attached to the system is not functioning.
thanks
I seriously made an account here JUST to post this post.
I've uploaded a revised version of this class that include summary tags. The only thing that these '''<SUMMARY> tags do is provide a description of the function/sub/property that you are typing within IntelliSense. It makes things MUCH easier. Attached is the revised class file. Import it into your project, and you'll notice that IntelliSence provided a description for the function/sub/property AND its arguments.
Another thing I noticed was the 'Try' and 'Do / Loop' Statements within the class:
Code:
Do
iBytesRead = sChunks.Read(bBuffer, 0, 256)
FS.Write(bBuffer, 0, iBytesRead)
iTotalBytesRead += iBytesRead
If myWebResponse.ContentLength < iTotalBytesRead Then
RaiseEvent AmountDownloadedChanged(myWebResponse.ContentLength)
Else
RaiseEvent AmountDownloadedChanged(iTotalBytesRead)
End If
Loop While Not iBytesRead = 0
This will cause your program to freeze and become unresponsive until the download finishes if you do not run the DownloadWithProgress() on a separate thread. You should use a "BackgroundWorker" and execute this. But before running the BackgroundWorker.RunWorkerAsync(), you have to set the global property 'CheckForIllegalThreadCalls' to FALSE or else an exception will be thrown. Heres an example:
Other then that, this is a very good class. It will come to use for custom install programs, file uploaders/downloaders, file share clients, and much more. Thanks a lot for the class!
You should always use Invoke(), BeginInvoke(), etc. instead of just disabling illegal thread call checks unless client-side performance is of the issue.
Invoke() and BeginInvoke() are much more difficult to use then a simple backgroundworker. This operation does not include any serious cross-thread calls other then changing some values of progress and file sizes. Unless after the operation is finished, you could re switch the thread call checks back to "true". How would you use Invoke() or BeginInvoke() anyway? i've never used them before.
Invoke() and BeginInvoke() are much more difficult to use then a simple backgroundworker. This operation does not include any serious cross-thread calls other then changing some values of progress and file sizes. Unless after the operation is finished, you could re switch the thread call checks back to "true". How would you use Invoke() or BeginInvoke() anyway? i've never used them before.
BackgroundWorker has a method called ReportProgress that uses Invoke in the background - disabling the check for illegal thread calls is not a good practice.
Invoke takes a delegate as a parameter and invokes the delegate on the UI thread.