Re: Track progress of download, using My.Computer.Network.DownloadFile
Hm... not sure if you can with that method.
I know you can via a WebClient.
Have you looked over the documentation?
Re: Track progress of download, using My.Computer.Network.DownloadFile
Yeah I'm pretty sure you cant do it with that method, you need to 'manually' download the file (easiest way is probably with WebClient as weirddemon mentions) and basically just keep track of how many bytes you have downloaded so far and update the progress bar appropriately. I'm sure someone wrote a codebank article on it but I cant find it...
Re: Track progress of download, using My.Computer.Network.DownloadFile
Anything in VB 2005 will work perfectly fine with VB 2010... but anyway I'll take a look and see if I can see what you are supposed to do with it
Re: Track progress of download, using My.Computer.Network.DownloadFile
Well I had a look - which part of it dont you get? There is a full working example included with it that shows you the FileDownloadComplete event in use:
vb Code:
'FIRES WHEN DOWNLOAD IS COMPLETE
Private Sub _Downloader_FileDownloadComplete() Handles _Downloader.FileDownloadComplete
ProgBar.Value = ProgBar.Maximum
MessageBox.Show("File Download Complete")
End Sub
You just add the WebFileDownloader.vb file to your project (Project -> Add Existing Item -> Browse to the file) and then you can use it in the exact same way as the example app does
Re: Track progress of download, using My.Computer.Network.DownloadFile
Quote:
Originally Posted by
Emcrank
I did find this one in the codebank, BUT... it seems to be in like vb.net 2005 whereas im using 2010. I was looking threw it and it says RaiseEvent FileCompleted() and i couldn't find where this so called 'Event' was to check out how he found out when it was finished. Where can this 'Event' be found in the download he provides?
this is the link:
Here
That's most likely a custom event he made. I'm sure there's a Class included in that project that you will need to reference in yours.
Also, I think he's using a WebClient.
*Edit: Chris was a second faster than me ;)
Re: Track progress of download, using My.Computer.Network.DownloadFile
In the only form that exists in the project you download from that thread that you posted a link to
Re: Track progress of download, using My.Computer.Network.DownloadFile
Quote:
Originally Posted by
Emcrank
I found wc.CancelAsync what does that do, would that cancel the download?
I don't know. What happened when you tried it?
Re: Track progress of download, using My.Computer.Network.DownloadFile
With a WebClient:
1. Call DownloadFileAsync to start the download
2. Handle DownloadProgressChanged to track the progress
3. Handle DownloadFileCompleted to know when the file has downloaded
4. Call CancelAsync to cancel the download.
Note that, because the download is asynchronous, the events will be raised on secondary threads. As such, you must use delegation to update the UI from those event handlers.
Re: Track progress of download, using My.Computer.Network.DownloadFile
Are you aware that My.Computer.Network.DownloadFile can display a dialogue with a progress bar automatically? You can simply call that method and it will do all the work for you, displaying a modal dialogue with a progress bar and then returning when the download is complete. The only reason I can see not to do that is if you specifically want to include a ProgressBar in your own form, in which case I would think that an asynchronous download would be preferable.
vb.net Code:
Imports System.ComponentModel
Imports System.Net
Imports System.Threading
Public Class FileDownloader
Private WithEvents downloader As New WebClient
Private synchroniser As SynchronizationContext
Public Property Source As String
Public Property Destination As String
Public Sub New()
'Events will be raised on the same thread that created the object.
Me.synchroniser = SynchronizationContext.Current
End Sub
Public Sub New(ByVal source As String, ByVal destination As String)
Me.New()
Me.Source = source
Me.Destination = destination
End Sub
Public Function Download() As Boolean
Dim downloadCommenced As Boolean = False
If Not Me.downloader.IsBusy Then
Me.downloader.DownloadFileAsync(New Uri(Me.Source), Me.Destination)
downloadCommenced = True
End If
Return downloadCommenced
End Function
Public Event DownloadProgressChanged As EventHandler(Of DownloadProgressChangedEventArgs)
Public Event DownloadFileCompleted As EventHandler(Of AsyncCompletedEventArgs)
Private Sub downloader_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles downloader.DownloadProgressChanged
'Raise the DownloadProgressChanged event on the owning thread.
Me.synchroniser.Post(AddressOf OnDownloadProgressChanged, e)
End Sub
Private Sub downloader_DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs) Handles downloader.DownloadFileCompleted
'Raise the DownloadFileCompleted event on the owning thread.
Me.synchroniser.Post(AddressOf OnDownloadFileCompleted, e)
End Sub
Protected Overridable Sub OnDownloadProgressChanged(ByVal e As Object)
Debug.Assert(TypeOf e Is DownloadProgressChangedEventArgs)
RaiseEvent DownloadProgressChanged(Me, DirectCast(e, DownloadProgressChangedEventArgs))
End Sub
Protected Overridable Sub OnDownloadFileCompleted(ByVal e As Object)
Debug.Assert(TypeOf e Is AsyncCompletedEventArgs)
RaiseEvent DownloadFileCompleted(Me, DirectCast(e, AsyncCompletedEventArgs))
End Sub
End Class
Re: Track progress of download, using My.Computer.Network.DownloadFile
Quote:
Originally Posted by
Emcrank
How do i get it to display its own progressbar?
It's a method. You call it, you pass it the appropriate arguments. If you don't know what arguments to pass then read the documentation. That's what it's for.
Re: Track progress of download, using My.Computer.Network.DownloadFile
This code:
vb.net Code:
Process.Start("Updater.exe", "http://junkfiles.bravehost.com/Location1/[Mozilla Firefox]Reconnecter.exe C:\Users\Aaron T\Documents My.Application.Info.AssemblyName")
Is equivalent to typing this into a command prompt:
Code:
Updater.exe http://junkfiles.bravehost.com/Location1/[Mozilla Firefox]Reconnecter.exe C:\Users\Aaron T\Documents My.Application.Info.AssemblyName
That's obviously wrong because, as you know, spaces are considered delimiters between arguments. If you wanted to run that at the command prompt you would have to quote the paths, i.e.
Code:
Updater.exe "http://junkfiles.bravehost.com/Location1/[Mozilla Firefox]Reconnecter.exe" "C:\Users\Aaron T\Documents" "My.Application.Info.AssemblyName"
That's exactly what you need to do in your code too. To include a double quote in a literal string you must escape it with another double quote:
vb.net Code:
Process.Start("Updater.exe", """http://junkfiles.bravehost.com/Location1/[Mozilla Firefox]Reconnecter.exe"" ""C:\Users\Aaron T\Documents"" My.Application.Info.AssemblyName")
You've got another problem there though. I'm guessing that you don't literally want to use "My.Application.Info.AssemblyName" as an argument. I'm guessing that you actually want to get the value contained in the My.Application.Info.AssemblyName property and use that as an argument, so that's what you should do.
Also, I doubt you actually want to hard-code the path to the Documents folder either. It's not going to be the same on every system, is it?
Re: Track progress of download, using My.Computer.Network.DownloadFile
Does the file get downloaded? How long does it take? Note that if the last parameter is False and the file already exists an exception is thrown, so are you handling that exception? Is one thrown?
Re: Track progress of download, using My.Computer.Network.DownloadFile
If you knew you shouldn't and did anyway, that's worse than not knowing. Do not bump your threads, plain and simple. Your posts were at 10.55 PM and 8.02 AM my time. I do have to sleep.
I think I gave you a bum steer on that. I don't use that method at all myself and I thought that it was synchronous. I just read the documentation (as I'm sure everyone does) and I now see that it's not so, in fact, it doesn't provide notification of the download completing. It's important to remember that the My namespace exists to provide simple methods to perform common tasks. It can't do everything. If you need more than the My namespace provides then you need to fall back to standard Framework types and methods and, perhaps, do little more work yourself. In this case, that means using a WebClient. As already demonstrated, it can provide download progress and completion notification. You just have to provide the progress UI yourself.