|
-
Aug 13th, 2010, 12:55 PM
#1
Thread Starter
Addicted Member
wait
hi there.
i have a problem
in VB i try to make a multi file downloader. but until now it downloads
all files at once to 1 file... (
i want my code to download all files to 1 FOLDER and the code must wait before starting another download
here is my code
VB.net Code:
Try
httpclient.DownloadFileAsync(New Uri(sourceURL), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
'effe wachten...
'klaar ga verder dan..
If CheckBoxX1.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL2), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX2.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL3), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX3.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL4), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX4.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL5), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX5.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL6), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX6.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL7), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX7.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL8), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX8.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL9), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
'effe wachten...
'klaar ga verder dan..
If CheckBoxX9.Checked = True Then
Try
httpclient.DownloadFileAsync(New Uri(sourceURL10), (filedir))
Catch ex As Exception
MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical)
End Try
End If
as u can see the sourceurl 1-10 has been programmed as textboxes (urls)
filedir must become the directory that the files must be downloaded to.
but imust type the name after it or it just doesnt start
any way to let
1. VB wait the code until download is completed then continue the code
2. download all files to 1 DIrectory
thanks
-
Aug 13th, 2010, 02:21 PM
#2
Re: wait
1. Since all the downloads is saved to the same (filedir) location, the later one will overwrite the previous one. You have to to provide a different file path for each download. You can have the same folder path but the file name has to be different for each download.
Code:
Dim downloadFolder as string = "put the full path to the folder you want to save here, for example C:\Downloads"
httpclient.DownloadFileAsync(New Uri(sourceURL1), downloadFolder & "\file1.xzy")
httpclient.DownloadFileAsync(New Uri(sourceURL2), downloadFolder & "\file2.xzy")
....
If you want to wait for the 1st download to complete before start the 2nd download, don't call DownloadFileAsync. Just call DownloadFile method because this is a blocking method.
Code:
httpClient.DownloadFile(url1, path1)
httpClient.DownloadFile(url2, path2)
.......................
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 13th, 2010, 03:01 PM
#3
Thread Starter
Addicted Member
Re: wait
well now it does not work anymore
i get this
VB.net Code:
System.Net.WebException was unhandled Message=Tijdens een WebClient-aanvraag is een uitzondering opgetreden. Source=System StackTrace: bij System.Net.WebClient.DownloadFile(Uri address, String fileName) bij System.Net.WebClient.DownloadFile(String address, String fileName) bij MC_downloader.Form1.ButtonItem1_Click(Object sender, EventArgs e) in C:\Users\mc pc\documents\visual studio 2010\Projects\MC downloader\MC downloader\Form1.vb:regel 33 bij DevComponents.DotNetBar.BaseItem.RaiseClick(eEventSource source) bij DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg) bij DevComponents.DotNetBar.PopupItem.InternalMouseUp(MouseEventArgs objArg) bij DevComponents.DotNetBar.ButtonItem.InternalMouseUp(MouseEventArgs objArg) bij DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg) bij DevComponents.DotNetBar.ItemContainer.InternalMouseUp(MouseEventArgs objArg) bij DevComponents.DotNetBar.ItemControl.OnMouseUp(MouseEventArgs e) bij DevComponents.DotNetBar.RibbonBar.OnMouseUp(MouseEventArgs e) bij System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bij System.Windows.Forms.Control.WndProc(Message& m) bij System.Windows.Forms.ScrollableControl.WndProc(Message& m) bij System.Windows.Forms.ContainerControl.WndProc(Message& m) bij DevComponents.DotNetBar.ItemControl.WndProc(Message& m) bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) bij System.Windows.Forms.Application.Run(ApplicationContext context) bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) bij MC_downloader.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81 bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bij System.Threading.ThreadHelper.ThreadStart_Context(Object state) bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bij System.Threading.ThreadHelper.ThreadStart() InnerException: System.ArgumentException Message=Lege padnaam is niet geldig. Source=mscorlib StackTrace: bij System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) bij System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) bij System.Net.WebClient.DownloadFile(Uri address, String fileName) InnerException:
this is my code now
VB.net Code:
httpclient.DownloadFile(sourceURL, filedir) If CheckBoxX1.Checked = True Then httpclient.DownloadFile(sourceURL2, filedir) ProgressBarX2.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX2.Checked = True Then httpclient.DownloadFile(sourceURL3, filedir) ProgressBarX3.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX3.Checked = True Then httpclient.DownloadFile(sourceURL4, filedir) ProgressBarX4.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX4.Checked = True Then httpclient.DownloadFile(sourceURL5, filedir) ProgressBarX5.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX5.Checked = True Then httpclient.DownloadFile(sourceURL6, filedir) ProgressBarX6.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX6.Checked = True Then httpclient.DownloadFile(sourceURL7, filedir) ProgressBarX7.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX7.Checked = True Then httpclient.DownloadFile(sourceURL8, filedir) ProgressBarX8.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX8.Checked = True Then httpclient.DownloadFile(sourceURL9, filedir) ProgressBarX9.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX9.Checked = True Then httpclient.DownloadFile(sourceURL10, filedir) ProgressBarX10.Value = "100" End If
-
Aug 13th, 2010, 03:10 PM
#4
Re: wait
What is the error message? I can't read whatever language it is in the exception message you posted. Care to translate it to English?
What is the value of sourceURL and filedir variables when the exception is thrown?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 14th, 2010, 03:37 AM
#5
Thread Starter
Addicted Member
Re: wait
the error is that During a WebClient request is an exception occurred
url is a rar file on my webserver www.host-it.org/privatefile.rar
path to file = D:\downloads
i'm administrator on the pc.
the language is dutch
-
Aug 14th, 2010, 11:22 AM
#6
Thread Starter
Addicted Member
Re: wait
no more responce? can anyone solve this
-
Aug 14th, 2010, 12:06 PM
#7
Re: wait
You need to be very specific about the error.
-
Aug 14th, 2010, 12:10 PM
#8
Thread Starter
Addicted Member
Re: wait
well . my VB lang is dutch i alraidy given the error code and translation
(the download doesnt even start i get directly a error :
During a WebClient request is an exception occurred
)
nothing more nothing less.
any fix for this?
-
Aug 14th, 2010, 01:37 PM
#9
Re: wait
Assuming the error occurs during the .DownloadFile wrap them in a Try-Catch block and trap the exceptions listed here
http://msdn.microsoft.com/en-us/library/ms144194.aspx
-
Aug 14th, 2010, 01:48 PM
#10
Thread Starter
Addicted Member
Re: wait
now i dont get any error. but it doesnt start download. again
my full code:
VB.net Code:
Private WithEvents httpclient As WebClient Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Sub DownloadFile1( _ ByVal sourceURL As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile2( _ ByVal sourceURL2 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile3( _ ByVal sourceURL3 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile4( _ ByVal sourceURL4 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile5( _ ByVal sourceURL5 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile6( _ ByVal sourceURL6 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile7( _ ByVal sourceURL7 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile8( _ ByVal sourceURL8 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile9( _ ByVal sourceURL9 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile10( _ ByVal sourceURL10 As Uri, _ ByVal filedir As String _ ) End Sub Private Sub ButtonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem1.Click httpclient = New WebClient Dim sourceURL = TextBoxX2.Text Dim sourceURL2 = TextBoxX3.Text My.Resources.gear.Save(My.Computer.FileSystem.SpecialDirectories.Temp & "\tempicon.ico", Imaging.ImageFormat.Icon) NotifyIcon1.Icon = My.Resources.gear1 Refresh() NotifyIcon1.Text = "Downloading in progress - MC Downloader" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Downloading files" NotifyIcon1.BalloonTipTitle = "MC Downloader" NotifyIcon1.ShowBalloonTip(10000) Dim sourceURL3 = TextBoxX4.Text Dim sourceURL4 = TextBoxX5.Text Dim sourceURL5 = TextBoxX6.Text Dim sourceURL6 = TextBoxX7.Text Dim sourceURL7 = TextBoxX8.Text 'v Dim sourceURL8 = TextBoxX9.Text Dim sourceURL9 = TextBoxX10.Text Dim sourceURL10 = TextBoxX11.Text Dim filedir As String = TextBoxX1.Text filedir = TextBoxX1.Text DownloadFile1(New Uri(sourceURL), filedir) If CheckBoxX1.Checked = True Then DownloadFile2(New Uri(sourceURL2), filedir) ProgressBarX2.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX2.Checked = True Then DownloadFile3(New Uri(sourceURL3), filedir) ProgressBarX3.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX3.Checked = True Then DownloadFile4(New Uri(sourceURL4), filedir) ProgressBarX4.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX4.Checked = True Then DownloadFile5(New Uri(sourceURL5), filedir) ProgressBarX5.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX5.Checked = True Then DownloadFile6(New Uri(sourceURL6), filedir) ProgressBarX6.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX6.Checked = True Then DownloadFile7(New Uri(sourceURL7), filedir) ProgressBarX7.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX7.Checked = True Then DownloadFile8(New Uri(sourceURL8), filedir) ProgressBarX8.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX8.Checked = True Then DownloadFile9(New Uri(sourceURL9), filedir) ProgressBarX9.Value = "100" End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX9.Checked = True Then DownloadFile10(New Uri(sourceURL10), filedir) ProgressBarX10.Value = "100" End If If ProgressBarX1.Value > "99" Then NotifyIcon1.Icon = My.Resources.tick1 NotifyIcon1.Text = "Done - MC Downloader" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Downloading finished" NotifyIcon1.BalloonTipTitle = "MC Downloader" NotifyIcon1.ShowBalloonTip(10000) ProgressBarX1.Refresh() End If End Sub
-
Aug 14th, 2010, 02:11 PM
#11
Re: wait
FTD-er? 
The Exception you gave earlier says that one of the path's is empty. Not sure though whether it's the URL or the filepath.
What is the line at which the error occurs?
Delete it. They just clutter threads anyway.
-
Aug 14th, 2010, 02:18 PM
#12
Thread Starter
Addicted Member
Re: wait
i dont get a error now. it just doesnt start the download. so thats a problem...
ps. DBP.er (ex FTDer)
-
Aug 14th, 2010, 02:21 PM
#13
Re: wait
I don't see the Try-Catch..
-
Aug 15th, 2010, 03:47 AM
#14
Thread Starter
Addicted Member
Re: wait
i did that see my code:
VB.net Code:
Private WithEvents httpclient As WebClient Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Sub DownloadFile1( _ ByVal sourceURL As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile2( _ ByVal sourceURL2 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile3( _ ByVal sourceURL3 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile4( _ ByVal sourceURL4 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile5( _ ByVal sourceURL5 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile6( _ ByVal sourceURL6 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile7( _ ByVal sourceURL7 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile8( _ ByVal sourceURL8 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile9( _ ByVal sourceURL9 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile10( _ ByVal sourceURL10 As Uri, _ ByVal filedir As String _ ) End Sub Private Sub ButtonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem1.Click httpclient = New WebClient Dim sourceURL = TextBoxX2.Text Dim sourceURL2 = TextBoxX3.Text My.Resources.gear.Save(My.Computer.FileSystem.SpecialDirectories.Temp & "\tempicon.ico", Imaging.ImageFormat.Icon) NotifyIcon1.Icon = My.Resources.gear1 Refresh() NotifyIcon1.Text = "Downloading in progress - MC Downloader" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Downloading files" NotifyIcon1.BalloonTipTitle = "MC Downloader" NotifyIcon1.ShowBalloonTip(10000) Dim sourceURL3 = TextBoxX4.Text Dim sourceURL4 = TextBoxX5.Text Dim sourceURL5 = TextBoxX6.Text Dim sourceURL6 = TextBoxX7.Text Dim sourceURL7 = TextBoxX8.Text 'v Dim sourceURL8 = TextBoxX9.Text Dim sourceURL9 = TextBoxX10.Text Dim sourceURL10 = TextBoxX11.Text Dim filedir As String = TextBoxX1.Text filedir = TextBoxX1.Text Try DownloadFile1(New Uri(sourceURL), filedir) Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try If CheckBoxX1.Checked = True Then Try DownloadFile2(New Uri(sourceURL2), filedir) ProgressBarX2.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX2.Checked = True Then Try DownloadFile3(New Uri(sourceURL3), filedir) ProgressBarX3.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX3.Checked = True Then Try DownloadFile4(New Uri(sourceURL4), filedir) ProgressBarX4.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX4.Checked = True Then Try DownloadFile5(New Uri(sourceURL5), filedir) ProgressBarX5.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX5.Checked = True Then Try DownloadFile6(New Uri(sourceURL6), filedir) ProgressBarX6.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX6.Checked = True Then Try DownloadFile7(New Uri(sourceURL7), filedir) ProgressBarX7.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX7.Checked = True Then Try DownloadFile8(New Uri(sourceURL8), filedir) ProgressBarX8.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX8.Checked = True Then Try DownloadFile9(New Uri(sourceURL9), filedir) ProgressBarX9.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX9.Checked = True Then Try DownloadFile10(New Uri(sourceURL10), filedir) ProgressBarX10.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If If ProgressBarX1.Value > "99" Then NotifyIcon1.Icon = My.Resources.tick1 NotifyIcon1.Text = "Done - MC Downloader" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Downloading finished" NotifyIcon1.BalloonTipTitle = "MC Downloader" NotifyIcon1.ShowBalloonTip(10000) ProgressBarX1.Refresh() End If
a still no error in screen nothing. nothing in the debug window it just doesnt start downloading
-
Aug 15th, 2010, 09:11 AM
#15
Thread Starter
Addicted Member
-
Aug 16th, 2010, 07:22 AM
#16
Re: wait
You still haven't told us what the value of filedir was exactly when the exception was thrown. From your other posts, it looks like you're passing in a folder path to the DownloadFile method instead of a file path.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 16th, 2010, 08:34 AM
#17
Thread Starter
Addicted Member
Re: wait
thats what i want a folder path. the filenames of the downloads must stay intact
-
Aug 16th, 2010, 10:20 AM
#18
Junior Member
Re: wait
If i am right you need to specify the folder and file of where you want to download to...
such as:
Code:
DownloadFile1(New Uri(sourceURL), filedir & "\file1.rar")
or something of the sorts
-
Aug 16th, 2010, 10:42 AM
#19
Re: wait
 Originally Posted by mmuziek
thats what i want a folder path. the filenames of the downloads must stay intact
Then you have to parse the file name from you download url and append it to the save path. For example:
Code:
Dim url as string = "http://www.somedomain.com/downloadme.txt"
'Since you already know what the download url is (otherwise, how are you going to download the file???), you simply parse that to get the filename.
'In this example, the file name is everything after the last forward slash in the download url. So you just substring it to get the file name
Dim filename as string = url.substring(url.LastIndexOf("/") + 1)
'And append the file name to the folder path
Dim saveTo as string = folderPath & "\" & filename
myWebClient.DownloadFile(url, saveTo)
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 16th, 2010, 11:55 AM
#20
Thread Starter
Addicted Member
Re: wait
added it still it doesnt start any download it starts and finish the code but it doesnt download anything.
ps. the progressbar doesnt work to with normal downloadfile command.
well my code now:
VB.net Code:
Imports System.Net Public Class Form1 Private WithEvents httpclient As WebClient Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Sub DownloadFile1( _ ByVal sourceURL As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile2( _ ByVal sourceURL2 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile3( _ ByVal sourceURL3 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile4( _ ByVal sourceURL4 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile5( _ ByVal sourceURL5 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile6( _ ByVal sourceURL6 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile7( _ ByVal sourceURL7 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile8( _ ByVal sourceURL8 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile9( _ ByVal sourceURL9 As Uri, _ ByVal filedir As String _ ) End Sub Public Sub DownloadFile10( _ ByVal sourceURL10 As Uri, _ ByVal filedir As String _ ) End Sub Private Sub ButtonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem1.Click httpclient = New WebClient Dim sourceURL = TextBoxX2.Text Dim sourceURL2 = TextBoxX3.Text My.Resources.gear.Save(My.Computer.FileSystem.SpecialDirectories.Temp & "\tempicon.ico", Imaging.ImageFormat.Icon) NotifyIcon1.Icon = My.Resources.gear1 Refresh() NotifyIcon1.Text = "Downloading in progress - MC Downloader" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Downloading files" NotifyIcon1.BalloonTipTitle = "MC Downloader" NotifyIcon1.ShowBalloonTip(10000) Dim sourceURL3 = TextBoxX4.Text Dim sourceURL4 = TextBoxX5.Text Dim sourceURL5 = TextBoxX6.Text Dim sourceURL6 = TextBoxX7.Text Dim sourceURL7 = TextBoxX8.Text 'v Dim sourceURL8 = TextBoxX9.Text Dim sourceURL9 = TextBoxX10.Text Dim sourceURL10 = TextBoxX11.Text Dim filedir As String = TextBoxX1.Text filedir = TextBoxX1.Text Try Dim filename As String = sourceURL.Substring(sourceURL.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile1(New Uri(sourceURL), saveTo) ProgressBarX2.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try If CheckBoxX1.Checked = True Then Try Dim filename As String = sourceURL2.Substring(sourceURL2.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile2(New Uri(sourceURL2), saveTo) ProgressBarX3.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX2.Checked = True Then Try Dim filename As String = sourceURL3.Substring(sourceURL3.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile3(New Uri(sourceURL3), saveTo) ProgressBarX4.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX3.Checked = True Then Try Dim filename As String = sourceURL4.Substring(sourceURL4.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile4(New Uri(sourceURL4), saveto) ProgressBarX5.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX4.Checked = True Then Try Dim filename As String = sourceURL5.Substring(sourceURL5.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile5(New Uri(sourceURL5), saveTo) ProgressBarX6.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX5.Checked = True Then Try Dim filename As String = sourceURL6.Substring(sourceURL6.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile6(New Uri(sourceURL6), saveTo) ProgressBarX7.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX6.Checked = True Then Try Dim filename As String = sourceURL7.Substring(sourceURL7.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile7(New Uri(sourceURL7), saveTo) ProgressBarX8.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX7.Checked = True Then Try Dim filename As String = sourceURL8.Substring(sourceURL8.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile8(New Uri(sourceURL8), saveTo) ProgressBarX9.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX8.Checked = True Then Try Dim filename As String = sourceURL9.Substring(sourceURL9.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile9(New Uri(sourceURL9), saveTo) ProgressBarX10.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If 'effe wachten... 'klaar ga verder dan.. If CheckBoxX9.Checked = True Then Try Dim filename As String = sourceURL10.Substring(sourceURL10.LastIndexOf("/") + 1) 'And append the file name to the folder path Dim saveTo As String = filedir & "\" & filename DownloadFile10(New Uri(sourceURL10), saveto) ProgressBarX11.Value = "100" Catch ex As Exception MsgBox("Failed " + ErrorToString(), MsgBoxStyle.Critical) End Try End If If ProgressBarX1.Value > "99" Then NotifyIcon1.Icon = My.Resources.tick1 NotifyIcon1.Text = "Done - MC Downloader" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Downloading finished" NotifyIcon1.BalloonTipTitle = "MC Downloader" NotifyIcon1.ShowBalloonTip(10000) ProgressBarX1.Refresh() End If End Sub Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click Dim save As New FolderBrowserDialog save.Description = "Download Directory" save.ShowDialog() TextBoxX1.Text = save.SelectedPath End Sub Private Sub httpclient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles httpclient.DownloadFileCompleted End Sub Private Sub httpclient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged ProgressBarX1.Value = e.ProgressPercentage End Sub
-
Aug 16th, 2010, 12:07 PM
#21
Re: wait
The code you posted does not have any code in the subs named DownloadFilex. So when you do this
DownloadFilex(New Uri(sourceURL), saveTo)
nothing should happen.
-
Aug 16th, 2010, 12:08 PM
#22
Junior Member
Re: wait
I could be wrong but it doesn't look like your subs are doing anything.
Code:
Public Sub DownloadFile1( _ ByVal sourceURL As Uri, _ ByVal filedir As String _) End Sub
It looks to me like they are just stubs. Shouldn't there be more code in there? maybe something like:
Code:
Dim wc As New System.Net.WebClient
wc.DownloadFile(uri, folder & "\" & file)
-
Aug 16th, 2010, 03:53 PM
#23
Thread Starter
Addicted Member
Re: wait
i fixed it completely with my friend Coi the best VB coder i can think off.
hes great at coding and helped me live with it so i can continue my work.
but all at once a conclusion
i learned a lot in this topic thank u all!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|