-
Jun 11th, 2008, 10:30 AM
#41
New Member
Re: Download Files From Web With Progressbar
hello people, this is my first post...
First, best regards for kleinma, this is what i need for my project for school,
i know that old thread but must try...
i need to figure the whole core so i can adjust it and put in my project...
here is a question:
why i need this ??? it is a property ok, but in whe class it only use first line mCurrentFille, i didnt see the roll of property... i have remove it and it still works..... so why ? ))
Code:
Private mCurrentFile As String = String.Empty
Public ReadOnly Property CurrentFile() As String
Get
Return mCurrentFile
End Get
End Property
back to work... more questions to come ))
i need to figure it out how to fix bug with "after close it still downloads"
also for my project i need to download list of url's......... my app generates web urls and i need to download it all..... i need to figure it out how... maybe some loop...
great work !!!
-
Jun 11th, 2008, 10:40 AM
#42
Re: Download Files From Web With Progressbar
It is really just a helper property incase you want to access the name of the file being downloaded by the downloader class, from the code that calls the download.
So in the example app, there is code in the form that handles the _Downloader.FileDownloadComplete event.
It looks like this:
Code:
'FIRES WHEN DOWNLOAD IS COMPLETE
Private Sub _Downloader_FileDownloadComplete() Handles _Downloader.FileDownloadComplete
ProgBar.Value = ProgBar.Maximum
MessageBox.Show("File Download Complete")
End Sub
However you could do something like this using that property:
Code:
'FIRES WHEN DOWNLOAD IS COMPLETE
Private Sub _Downloader_FileDownloadComplete() Handles _Downloader.FileDownloadComplete
ProgBar.Value = ProgBar.Maximum
MessageBox.Show("File Download for " & _Downloader.CurrentFile & " Complete")
End Sub
Another option would be making a custom eventargs to pass to that event that includes the filename of the downloaded file instead, I just didn't make it that robust because I did not have a need to for the app I coded this for originally.
-
Jun 12th, 2008, 07:30 AM
#43
New Member
Re: Download Files From Web With Progressbar
True True, thx for fast reply...
i have put some check for URL that user type in...
if user put http:// or if not, app will put...
before that app report error... and user must type WHOLE url... and we know how users are )))))))))
Code:
in
Private Sub cmdDownload_Click
If Mid(txtURL.Text, 1, 7) <> "http://" Then
Dim temp, http As String
temp = txtURL.Text
http = "http://"
txtURL.Text = http & temp
End If
------------- continue core
'Download
Try
_Downloader = New WebFileDownloader
_Downloader.DownloadFileWithProgress(txtURL.Text, txtDownloadTo.Text.TrimEnd("\"c) & GetFileNameFromURL(txtURL.Text))
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
End Sub
but i have one problem:
i have form1, and on form1 i have button, when click form2 pop up...
but if i close form1 form2 also will be closed... how can i make form2 stay?
AND what is key word for checking IS FORM2 ACTIVE ? of IS FORM2 opened?
thx
SxOne
Last edited by S-One; Jun 12th, 2008 at 08:33 AM.
-
Jun 12th, 2008, 08:43 AM
#44
Re: Download Files From Web With Progressbar
What version of Visual Studio are you using?
In 2005 and above, there is a setting in project properties which says "Shutdown Mode" and it is set to "When Startup Form Closes" by default.
So if Form1 is your startup form, then closing it tells you app the whole thing should close. Change this value to "when last form closes" and that should solve your issue.
Form.ActiveForm will return the active form anywhere inside your application. It is a shared property so no instance is required to use it. It can however return a value of Nothing, in the event there is no active form.
-
Jun 12th, 2008, 10:08 AM
#45
New Member
Re: Download Files From Web With Progressbar
-
Jun 12th, 2008, 10:12 AM
#46
New Member
Re: Download Files From Web With Progressbar
hey do you have some idea how can i download more then one file from web... some loop
actually let me explain...
i have app that generates list of url's
after that a need to download it all....
i have an idea that maybe its best to put them in .txt file and forward it to your Download app.....
i need to figure it how...
out to work on it
-
Jun 12th, 2008, 10:25 AM
#47
Re: Download Files From Web With Progressbar
I guess it depends on if you want to download one file at a time, or all of them at once. It was not really designed to perform multiple async downloads at the same time, however if you are just talking about downloading multiple files, one after another, then it could be as simple as making a list of files to download, and in the download complete event that fires off when a download has completed, you simply kick off the call to download the next file, until all files have been downloaded.
-
Jun 12th, 2008, 12:05 PM
#48
New Member
Re: Download Files From Web With Progressbar
yes, i mean one file at a time, not multiple...
thanks for idea, i will try that !!!
-
Jun 14th, 2008, 09:11 PM
#49
New Member
Re: Download Files From Web With Progressbar
Originally Posted by sdk1985
Also there are some ! according to VB with the default project. (I am now using an exact copy of webfiledownloader.vb in my program)
Warning 1 Variable 'FS' is used before it has been assigned a value. A null reference exception could result at runtime. I:\Documents and Settings\Sebas\Mijn documenten\Visual Studio 2005\Projects\FileTransfer\FileTransfer\WebFileDownloader.vb 70 21 FileTransfer
Warning 2 Function 'FormatFileSize' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. I:\Documents and Settings\Sebas\Mijn documenten\Visual Studio 2005\Projects\FileTransfer\FileTransfer\WebFileDownloader.vb 99 5 FileTransfer
Hmm, i have converter my project from .net 2003 to 2005 and i also get this Warning, weird, but there is return
also i get warning abour DialogResult.no, yes, or whatever is used...
i have resolved this with
Code:
System.Windows.Forms.DialogResult....
EDIT:
ok i have resolved FormatFileSize Warning Case else is missing:
Code:
Select Case Size / KB
Case Is < 1000
Return (Size / KB).ToString("N") & "KB"
Case Is < 1000000
Return (Size / MB).ToString("N") & "MB"
Case Is < 10000000
Return (Size / MB / KB).ToString("N") & "GB"
Case Else
Return Size.ToString & "bytes"
End Select
Matt can you explain this please ("D" & "N" is format right):
Size.ToString("D") .ToString("N")
also cant find help about URL.IndexOf("/"c) and URL.LastIndexOf("/"c)
what is c for ? (description is Char, but please explain
thx in advance !
Last edited by S-One; Jun 14th, 2008 at 09:29 PM.
-
Jun 16th, 2008, 01:10 PM
#50
Re: Download Files From Web With Progressbar
Originally Posted by S-One
Hmm, i have converter my project from .net 2003 to 2005 and i also get this Warning, weird, but there is return
also i get warning abour DialogResult.no, yes, or whatever is used...
i have resolved this with
Code:
System.Windows.Forms.DialogResult....
EDIT:
ok i have resolved FormatFileSize Warning Case else is missing:
Code:
Select Case Size / KB
Case Is < 1000
Return (Size / KB).ToString("N") & "KB"
Case Is < 1000000
Return (Size / MB).ToString("N") & "MB"
Case Is < 10000000
Return (Size / MB / KB).ToString("N") & "GB"
Case Else
Return Size.ToString & "bytes"
End Select
Matt can you explain this please ("D" & "N" is format right):
Size.ToString("D") .ToString("N")
also cant find help about URL.IndexOf("/"c) and URL.LastIndexOf("/"c)
what is c for ? (description is Char, but please explain
thx in advance !
Yeah this project was originally done in VS2003 (.NET 1.1) they added in some warnings in the newer versions of VS, so that is what you were seeing.
Those fixes you made were fine.
"D" is for decimal formatting of a number as a string, and "N" is for general number formatting of a number as a string. In some cases, they may yield the same result, and in others they will not. (usually has to do with number of decimal place precision, etc..)
Here is a listing of valid numeric formats for calling ToString
http://msdn.microsoft.com/en-us/libr...9k(VS.80).aspx
The IndexOf method is a method that simply returns the numeric index of where a given character is in a string of characters.
So given the string "abccba", the character positions of the letters are as follows:
a = 0
b = 1
c = 2
c = 3
b = 4
a = 5
So if I were to get the indexof("a"c), it will return 0, as a is found at position 0 in this string, however getting lastindexof("a") does the same thing, but starts at the end of the string, in which case it will find a in position 5, so it will return a 5.
the c after the specified character is just to tell the compiler "this is a datatype char, not a string with only 1 character". By default VB thinks anything in quotes is a string.
-
Jun 16th, 2008, 04:28 PM
#51
New Member
Re: Download Files From Web With Progressbar
thanks Matt !!!
great answer !!!
-
Jun 17th, 2008, 10:00 AM
#52
New Member
Re: Download Files From Web With Progressbar
Hey Matt, can i ask for one more thing, can you help me how to delete file that didnt whole downloaded, i made Cancel button but cant figure it out where to put delete method, and which is a delete method...
is this enough to Flush all buffers from memory or need something more ?
Code:
If Cancel = True Then
sChunks.Close()
FS.Close()
FS = Nothing
RaiseEvent CancelResetLabelText()
Return False
End If
this is in "DownloadFileWithProgress" Do While Loop
i need this for school project so if you can please help me...
-
Jun 23rd, 2008, 11:25 PM
#53
New Member
Re: Download Files From Web With Progressbar
i have resolved problem with deleting non downloaded file.
In "DownloadFileWithProgress" function in Do While Loop, i have added Cancel option before and in that part i have added this line:
My.Computer.FileSystem.DeleteFile(Location.ToString)
[code]
Do
If Cancel = True Then
sChunks.Close()
FS.Close()
FS = Nothing
My.Computer.FileSystem.DeleteFile(Location.ToString)
RaiseEvent CancelResetLabelText()
Return False
End If
.................
[code]
it works great file is deleted if it's canceled, so now my project is finished... i will post Screenshots later...
thanks again matt for Help, and fot this application !!!!!!!!!!!
Best Regards,
ShOne from Serbia
-
Jul 30th, 2008, 01:10 PM
#54
Lively Member
Re: Download Files From Web With Progressbar
superb script.
Quick question, is it possible to modify to download a web folders contents as opposed to a file???
cheers
-
Jul 30th, 2008, 01:13 PM
#55
Re: Download Files From Web With Progressbar
it downloads the file over HTTP, so if you knew the specific file names, then of course you could run it in a loop and download each file.
If you mean can you point it to a folder location on the web, and have it download every file without knowing their names, then no. A webserver doesn't serve up the list of files in a given folder unless directory browsing is on. If directory browsing was on, you could in theory navigate to the directory, parse the list of files, and then download them individually because you would now have their names.
If you were to go a different route, like FTP if it were possible for you, then you can do things like list the contents of a directory without downloading anything, and then download the entire directories contents.
-
Jul 30th, 2008, 01:25 PM
#56
Lively Member
-
Jul 30th, 2008, 01:55 PM
#57
Re: Download Files From Web With Progressbar
you would want to download the HTML that is output by your webserver when you visit that page, and parse it to get the file names. Once you have each individual file name in a collection or an array, then you could use my code in this thread to loop and download each file.
You should really start a new thread in the VB.NET section of this forum, asking about downloading and parsing a file list from a website with directory browsing on.
-
Jul 30th, 2008, 03:27 PM
#58
Lively Member
Re: Download Files From Web With Progressbar
Matt,
Will do thanks for directing me in the right direction.
Your script is a real diamond
-
Jul 30th, 2008, 03:30 PM
#59
Re: Download Files From Web With Progressbar
Check back soon, I am working on a new version which has a few extra features.
-
Sep 3rd, 2008, 04:16 PM
#60
New Member
Re: Download Files From Web With Progressbar
Hey Matt, me again
Can you explain to me why did you wrote this line ?
Dim myWebResponse As WebResponse = myWebRequest.GetResponse
i understand first part, but why did you initializes it ?? and what did you get with it ?
also this line same question
Dim myStream As Stream = myWebResponse.GetResponseStream
thx in advance...
Sxone
Last edited by S-One; Sep 3rd, 2008 at 04:31 PM.
-
Sep 3rd, 2008, 04:38 PM
#61
Re: Download Files From Web With Progressbar
You don't get a response from your request to download a file until you call the GetResponse method. When you do that, the response is returned from the class as a WebResponse object.
So that line of code
Dim myWebResponse As WebResponse = wRemote.GetResponse
is saying
Declare myWebResponse as a WebResponse object and set it to the response from the WebRequest called myWebRequest.
So once you create your webrequest to download the file, you need to check the response. That is how the stateless nature of the web works, through requests from you and responses from web servers.
-
Sep 3rd, 2008, 06:58 PM
#62
-
Sep 4th, 2008, 09:21 AM
#63
Re: Download Files From Web With Progressbar
I just post on here to help out so others can learn how to program too. I love VB so I always like to help out those who are learning it.
-
Sep 14th, 2008, 08:32 PM
#64
Hyperactive Member
Re: Download Files From Web With Progressbar
Ya the code works but there is one problem first of all it takes about five seconds before the message shows saying "Connection Found!" Second of all it freezes after the message comes up it wont allow any buttons to be clicked! I am using Microsoft Visual Basic 2008 Windows XP SP2
-
Oct 7th, 2008, 10:56 AM
#65
Addicted Member
Re: Download Files From Web With Progressbar
hia sorry mate for User login section i didn't get erectly..
can u assist me how can i make users that download files from Rapidshare or megaupload or mxupload to be able to log with their premium account..
< advertising link removed by moderator >
-
Oct 7th, 2008, 11:02 AM
#66
Re: Download Files From Web With Progressbar
you should open a new thread in the VB.NET section on that. Questions here should only pertain to the specific code in the codebank submission.
-
Oct 7th, 2008, 12:40 PM
#67
Addicted Member
Re: Download Files From Web With Progressbar
is your download manager you had made just want to add User login to that download manager thets all...
< advertising link removed by moderator >
-
Oct 7th, 2008, 12:49 PM
#68
Re: Download Files From Web With Progressbar
those file services require HTTP form based logins, so your actual question really should be how to perform that authentication prior to using my download code.
That is what belongs in its own thread. This web file downloader example code I have posted here is for non password protected file downloads.
-
Nov 22nd, 2008, 04:55 AM
#69
New Member
Re: Download Files From Web With Progressbar
Hi, It's really a gem of Code. I need some help. How to show the estimated time, elapsed time, time remaining, etc when the file is downloading?
-
Nov 22nd, 2008, 05:41 AM
#70
New Member
Re: Download Files From Web With Progressbar
I have a situation where i have two buttons and on clicking button1 i can download abc.rar and on clicking button2 i can download xyz.rar. I used your webfiledownloader class. Now my problem is that before the abc.rar is downloaded completely i clicked on button2 which will start downloading xyz.rar by stopping abc.rar. How to make xyz.rar to wait till abc.rar is finished?
-
Dec 4th, 2008, 10:42 PM
#71
New Member
Re: Download Files From Web With Progressbar
How to show estimated time, remaining time, download speed, etc when the file is downloading in this WebFileDownloader class?
-
Dec 13th, 2008, 07:47 AM
#72
Addicted Member
Re: Download Files From Web With Progressbar
ehm...
I get this error in the DownloadFileWithProgress function;
vb.net Code:
FS = New FileStream(Location, FileMode.Create, FileAccess.Write)
"Access to the path 'C:\' was denied"
Im running win xp, and there's only one user and it got full admin rights...
-
Dec 18th, 2008, 04:35 PM
#73
Re: Download Files From Web With Progressbar
what is the actual value of the "Location" variable when that occurs?
Also, can the user manually create a file on the root of C?
-
Dec 21st, 2008, 11:04 PM
#74
New Member
Re: Download Files From Web With Progressbar
How to show estimated time, remaining time, download speed, etc when the file is downloading in this WebFileDownloader class?
-
Dec 22nd, 2008, 09:41 AM
#75
Re: Download Files From Web With Progressbar
you would need to calculate all those things on your own. You should develop each forumla first, like time remaining is an estimate based on the amount currently downloaded, the total file size, and the download speed.
I haven't worked these types of features into this code, but feel free to work it in, and post back with your results.
-
Dec 22nd, 2008, 10:01 AM
#76
Hyperactive Member
Re: Download Files From Web With Progressbar
Kleinma could you help me to get this to report progress please? It uses .NetWebrequest as in your class.
Also is there any downfalls to using this?
vb.net Code:
Public Class Form1 Private Const filenames As String = "c:\Users\Home\Desktop\list_of_files.txt" Private Const url As String = "http://www.fileden.com/files/2008/12/22/2233952" Private Const savepath As String = "c:\Users\Home\Desktop\" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim sr As New IO.StreamReader(filenames) Dim line As String = sr.ReadLine() Dim req As Net.WebRequest Dim resp As IO.Stream Dim out As IO.BinaryWriter Do While line IsNot Nothing req = Net.HttpWebRequest.Create(url & line) resp = req.GetResponse().GetResponseStream() out = New IO.BinaryWriter(New IO.FileStream(savepath & line, IO.FileMode.OpenOrCreate)) Dim buf(4096) As Byte Dim k As Int32 = resp.Read(buf, 0, 4096) Do While k > 0 out.Write(buf, 0, k) k = resp.Read(buf, 0, 4096) Loop resp.Close() out.Close() line = sr.ReadLine() Loop Catch i As Exception MsgBox(i.ToString) End Try End Sub End Class
-
Jan 9th, 2009, 12:25 PM
#77
Addicted Member
Re: Download Files From Web With Progressbar
Originally Posted by kleinma
what is the actual value of the "Location" variable when that occurs?
Also, can the user manually create a file on the root of C?
Sorry for being so late, i totally forgot this. I have gotten a new hd lately (christmas), and it still says the same thing.
i changed the path to "C:\Documents and Settings\Steffenn\Skrivebord", still gets access denied.
also tried C:\, same.
-
Jan 9th, 2009, 01:34 PM
#78
New Member
Re: Download Files From Web With Progressbar
Thank you for posting this example. I've been looking for ways to download large files with a look like you created.
So far I've tested this to handle up to 480 MB with no problems
-
Jan 11th, 2009, 10:44 PM
#79
New Member
Re: Download Files From Web With Progressbar
Thanks for your advice. I will try it on my own.
Originally Posted by kleinma
you would need to calculate all those things on your own. You should develop each forumla first, like time remaining is an estimate based on the amount currently downloaded, the total file size, and the download speed.
I haven't worked these types of features into this code, but feel free to work it in, and post back with your results.
-
Feb 9th, 2009, 02:20 PM
#80
New Member
Re: Download Files From Web With Progressbar
hey, i am having some problems making the cancel button. I used the code provided by s-one:
Code:
Do
If Cancel = True Then
sChunks.Close()
FS.Close()
FS = Nothing
My.Computer.FileSystem.DeleteFile(Location.ToString)
RaiseEvent CancelResetLabelText()
Return False
End If
how would i call this with a button? what do you need to declare in the frmmain.vb and webfiledownloader.vb? thanks...
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
|