-
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.
-
Re: Download Files From Web With Progressbar
Niiice ;)
thanks very much...
if there is something i can do for you, like Upload something, ANYTHING, just say, you have helped me a lot with your example and code support :)
i have use some of your code in my project (like i sad before) for school, it is over, but i need to write report, so i'm learning how does it works...
maybe i will ask you something more, if i need :P
thanks a lot again
SxOne
-
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.
-
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
-
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..
-
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.
-
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...
-
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.
-
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?
-
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?
-
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?
-
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...
-
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?
-
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?
-
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.
-
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
-
Re: Download Files From Web With Progressbar
Quote:
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.
-
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
-
Re: Download Files From Web With Progressbar
Thanks for your advice. I will try it on my own.
Quote:
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.
-
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...
-
Re: Download Files From Web With Progressbar
there is a way i can retrive the download speed?
-
Re: Download Files From Web With Progressbar
Hello kleinma
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.
Could you point me in the right direction?
Thank you in advance.
-
Re: Download Files From Web With Progressbar
what are the values of what you hard coded? The error is pretty clear that you are trying to use some path that you don't have access to.
-
Re: Download Files From Web With Progressbar
i have used "Application.StartupPath()" as download path.
-
Re: Download Files From Web With Progressbar
I could see that happening on a Vista machine. Is that what you are using?
-
Re: Download Files From Web With Progressbar
no i'm using XP media center 2005. But I have tested the program also on windows 2000 Pro... no way, access denied.
EDIT:
If it helps, I can post the script as i have changed it...
-
Re: Download Files From Web With Progressbar
I will take a look if you post it.
-
1 Attachment(s)
Re: Download Files From Web With Progressbar
OKI, here you are.
Thank you very much! :) :thumb:
-
Re: Download Files From Web With Progressbar
I'm guessing you did change some values in here before you uploaded it to protect some info right?
-
Re: Download Files From Web With Progressbar
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
-
Re: Download Files From Web With Progressbar
Quote:
Originally Posted by
kleinma
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...
Quote:
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. :thumb::thumb:
-
Re: Download Files From Web With Progressbar
Quote:
Originally Posted by
-Negative-
there is a way i can retrieve the download speed?
Thank you so much for this submission, it's helped me immensely
I too am looking for a simple way to retrieve the current download speed, any help would be very much appreciated
-
Re: Download Files From Web With Progressbar
Quote:
Originally Posted by
ph4nt0m
Thank you so much for this submission, it's helped me immensely
I too am looking for a simple way to retrieve the current download speed, any help would be very much appreciated
Speed is simply data transfered/time interval.
Do you know how to add in code to determine how much data has been received, and how to track how much time has elapsed?
-
Re: Download Files From Web With Progressbar
Well, i added a stopwatch and then the following to try to retrieve the current speed
Code:
currentspeed = iTotalBytesRead / (sTimer.ElapsedMilliseconds / 1000)
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
-
Re: Download Files From Web With Progressbar
Hi
thank you my brother , it is helpful
I have a question:
how to make a button to stop "downloading" process?? how to cancel the process??
waiting you
thanks
-
1 Attachment(s)
Re: Download Files From Web With Progressbar
I did it!!
I added new function named "StopDownload" and new Event "FileDownloadStopped"
download my file : WebFileDownloader.vb
then you can stop download process :
Code:
_Downloader.StopDownload()
Code:
Private Sub _Downloader_FileDownloadStopped() Handles _Downloader.FileDownloadStopped
'Write your code here
End Sub
:)
-
Re: Download Files From Web With Progressbar
Quote:
there is a way i can retrieve the download speed?
1 - add "Timer" , Timer1 .. then Set Interval=1000
2 - In general , write :
Code:
dim lastSize, cSize As Long
3 - In "_Downloader_AmountDownloadedChanged" , add :
Code:
lastSize = cSize
If Timer1.Enabled = False Then Timer1.Enabled = True
4 - In Timer1_Tick , write :
Code:
lblDownloadRate.Text = WebFileDownloader.FormatFileSize(cSize - lastSize)
lastSize = cSize
I hope that work fine...
it's work fine with me
your brother:
Abdulkareem
Saudi Arabia, Jazan
-
Re: Download Files From Web With Progressbar
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?
thanks..
-
Re: Download Files From Web With Progressbar
in theory yes you could do that.
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.
-
Re: Download Files From Web With Progressbar
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.
-
Re: Download Files From Web With Progressbar
Quote:
Originally Posted by
EndLessMind
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.
please read my reply :
http://www.vbforums.com/showpost.php...6&postcount=97
-
Re: Download Files From Web With Progressbar
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?
-
Re: Download Files From Web With Progressbar
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
-
Re: Download Files From Web With Progressbar
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.
-
Re: Download Files From Web With Progressbar
Quote:
Originally Posted by
kleinma
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
-
Re: Download Files From Web With Progressbar
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.
-
Re: Download Files From Web With Progressbar
Quote:
Originally Posted by
kleinma
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.
has you an sample code
-
Re: Download Files From Web With Progressbar
Code:
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)
-
Re: Download Files From Web With Progressbar
where must i past this code?
-
Re: Download Files From Web With Progressbar
Wherever you update the progress bar. I haven't actually looked at the control yet, this was just obvious.
-
Re: Download Files From Web With Progressbar
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).
-
Re: Download Files From Web With Progressbar
nice code... thx for sharing =)
-
Re: Download Files From Web With Progressbar
@Legjendat: Check my signature for my Asynchronous Downloading File System Class.
-
Re: Download Files From Web With Progressbar
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
-
1 Attachment(s)
Re: Download Files From Web With Progressbar
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:
Code:
CheckForIllegalThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
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!
-
Re: Download Files From Web With Progressbar
You should always use Invoke(), BeginInvoke(), etc. instead of just disabling illegal thread call checks unless client-side performance is of the issue.
-
Re: Download Files From Web With Progressbar
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.
-
Re: Download Files From Web With Progressbar
i didnt even know you could download stuff with just a progress bar :x
-
Re: Download Files From Web With Progressbar
Quote:
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.
I'm talking about this:
Code:
CheckForIllegalThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
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.
-
Re: Download Files From Web With Progressbar
wow,
the codes work perfect thank for this sir kleinma,
thanks so much