Page 3 of 4 FirstFirst 1234 LastLast
Results 81 to 120 of 132

Thread: Download Files From Web With Progressbar

  1. #81
    Addicted Member
    Join Date
    Jan 2009
    Posts
    130

    Re: Download Files From Web With Progressbar

    there is a way i can retrive the download speed?

  2. #82
    New Member
    Join Date
    May 2009
    Posts
    7

    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.

  3. #83

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  4. #84
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: Download Files From Web With Progressbar

    i have used "Application.StartupPath()" as download path.

  5. #85

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Download Files From Web With Progressbar

    I could see that happening on a Vista machine. Is that what you are using?

  6. #86
    New Member
    Join Date
    May 2009
    Posts
    7

    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...
    Last edited by Antonidas; May 26th, 2009 at 10:55 AM.

  7. #87

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Download Files From Web With Progressbar

    I will take a look if you post it.

  8. #88
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: Download Files From Web With Progressbar

    OKI, here you are.

    Thank you very much!
    Attached Files Attached Files

  9. #89

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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?

  10. #90

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  11. #91
    New Member
    Join Date
    May 2009
    Posts
    7

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma View Post
    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 View Post
    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.

  12. #92
    New Member
    Join Date
    Jun 2009
    Posts
    2

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by -Negative- View Post
    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
    Last edited by ph4nt0m; Jun 2nd, 2009 at 05:10 PM.

  13. #93
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by ph4nt0m View Post
    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?
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  14. #94
    New Member
    Join Date
    Jun 2009
    Posts
    2

    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
    Last edited by ph4nt0m; Jun 3rd, 2009 at 04:09 PM.

  15. #95
    New Member
    Join Date
    Apr 2008
    Posts
    4

    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

  16. #96
    New Member
    Join Date
    Apr 2008
    Posts
    4

    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
    Attached Files Attached Files

  17. #97
    New Member
    Join Date
    Apr 2008
    Posts
    4

    Re: Download Files From Web With Progressbar

    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

  18. #98
    Lively Member
    Join Date
    Aug 2009
    Posts
    126

    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..

  19. #99

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  20. #100
    New Member
    Join Date
    Mar 2009
    Posts
    14

    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.

  21. #101
    New Member
    Join Date
    Apr 2008
    Posts
    4

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by EndLessMind View Post
    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

  22. #102
    New Member
    Join Date
    Mar 2009
    Posts
    14

    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?

  23. #103
    New Member
    Join Date
    Apr 2010
    Posts
    4

    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

  24. #104

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  25. #105
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma View Post
    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

  26. #106

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  27. #107
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma View Post
    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

  28. #108
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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)

  29. #109
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: Download Files From Web With Progressbar

    where must i past this code?

  30. #110
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  31. #111
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    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).

  32. #112
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Re: Download Files From Web With Progressbar

    nice code... thx for sharing =)

  33. #113

    Re: Download Files From Web With Progressbar

    @Legjendat: Check my signature for my Asynchronous Downloading File System Class.

  34. #114
    New Member
    Join Date
    Aug 2010
    Posts
    1

    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

  35. #115
    Junior Member
    Join Date
    Sep 2010
    Location
    Connecticut
    Posts
    17

    Exclamation 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!
    Attached Files Attached Files

  36. #116
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  37. #117
    Junior Member
    Join Date
    Sep 2010
    Location
    Connecticut
    Posts
    17

    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.

  38. #118
    Junior Member
    Join Date
    Sep 2010
    Posts
    17

    Re: Download Files From Web With Progressbar

    i didnt even know you could download stuff with just a progress bar :x

  39. #119
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.
    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.

  40. #120
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: Download Files From Web With Progressbar

    wow,
    the codes work perfect thank for this sir kleinma,


    thanks so much
    Last edited by eyestrain; Oct 7th, 2010 at 03:32 AM.

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width