Hello,
I'm currently programming in VB .NET 2005. I've got a working programme which downloads and saves the file to the location I choose but I have one problem.
If I download using DownloadFileAsync method of the webclient, I receive feedback on how much has been downloaded but I can't seem to queue another file as it fails the first file and begins the next. The only way to pause between the calls to the method DownloadAsync is to insert a messagebox.
Now I can solve this problem using the method DownloadFile of the webclient but then I don't get any feedback of how much of the file has been downloaded.
the method which calls the downloadasync,
Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
Dim ShowDialogue As Boolean = True
DownloadAsync(OnlineFileRef, ShowDialogue)
'MessageBox.Show("Download 1", "DownloadAsync", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
DownloadAsync(OnlineFileRef, False)
'DownloadFile(OnlineFileRef, ShowDialogue)
'DownloadFile(OnlineFileRef, False)
End Sub
the downloadasync method,
Private Sub DownloadAsync(ByVal URL As String, ByVal ShowDialogue As Boolean)
CurrentFile = CurrentFile + 1
Dim ZIPIndex As Integer = CurrentFile - 1
'AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgress
'AddHandler wc.DownloadFileCompleted, AddressOf DownloadComplete
Try
If ShowDialogue = True Then
SaveFileDialogue.DefaultExt = URL.Substring(URL.LastIndexOf( "."))
SaveFileDialogue.Filter = UCase(SaveFileDialogue.DefaultExt) + " File Type (*." + SaveFileDialogue.DefaultExt + ")|*" + SaveFileDialogue.DefaultExt
SaveFileDialogue.ShowDialog()
Else
URL = URL.Remove(URL.Length - 2, 2)
URL += "0" + ZIPIndex.ToString()
SaveFileDialogue.FileName = SaveFileDialogue.FileName.Substring(0, SaveFileDialogue.FileName.LastIndexOf( ".")) + URL.Substring(URL.LastIndexOf("."))
End If
Dim Address As New Uri(URL)
If (SaveFileDialogue.FileName <> "") Then
DownloadButton.Enabled = False
CancelDownloadButton.Enabled = True
If (wc.IsBusy = True) Then
wc.Dispose()
End If
wc.DownloadFileAsync(Address, SaveFileDialogue.FileName)
Else
CancelDownloadButton.Enabled = False
DownloadButton.Enabled = True
End If
Catch ex As Exception
SendMail( "(DownloadAsync)", ex.ToString())
MessageBox.Show( "Failed to completed download!", "Download failed", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
wc.Dispose()
CancelDownloadButton.Enabled = False
DownloadButton.Enabled = True
End Try
End Sub
Any Ideas Thanks for the help in advance!
.NET Development30
|