Download Files From Web With Progressbar-VBForums
Page 1 of 4 1234 LastLast
Results 1 to 40 of 129

Thread: Download Files From Web With Progressbar

  1. #1

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Download Files From Web With Progressbar

    Here is a sample project I did up that uses a class I wrote (WebFileDownloader)

    The WebFileDownloader class provides methods for downloading a file from a URL and firing events to update progress in the GUI on a progress bar or whatever you may like.

    The standard WebClient class in the .NET framework has a method for downloading a file, but there is no indication of its progress as it downloads, which is why I wrote this up.

    Known limitations:
    progress is returned as a long, and a progress bar takes an integer, so in the sample I convert the long to integer, which could error in BIG downloaded files.. a better solution would be to use the filesize being downloaded and calculate a good maximum to set the progress bar to. However this is GUI related, and not related to the WebFileDownloader class itself. (Just wanted to point it out)

    Also make sure the URL is a full URL (ie http://www.mysite.com/file.zip and not www.mysite.com/file.zip)

    Please post any corrections you may find. I use this code all the time, but that doesn't mean there isn't a bug or 2 lurking somewhere
    Attached Files Attached Files
    Last edited by kleinma; Mar 30th, 2006 at 03:42 PM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  2. #2
    Junior Member RingOfFire's Avatar
    Join Date
    May 2006
    Location
    Istanbul
    Posts
    28

    Re: Download Files From Web With Progressbar

    Thank you for the sample project.

    I have a question: When the user clicks the close button (or exits application) during a download, download procedure keeps going on.

    I'd like to know how to add the following feature:

    When the application is stopped somehow
    (by user, by system or other failure)

    1. Stop the download process
    2. Delete the file that was downloaded partially

  3. #3
    New Member dannyf's Avatar
    Join Date
    Aug 2006
    Posts
    1

    Re: Download Files From Web With Progressbar

    I noticed the buttons and progress bar in this project have the "XP" look.

    How did you do that?

    I can't find an option anywhere in Visual Studio?

    Edit: looking through the zip file I can't find any use of manifest files or anything either?
    Last edited by dannyf; Aug 28th, 2006 at 07:17 PM.

  4. #4

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    I enable visual styles in the Sub Main routine.

    This code here
    VB Code:
    1. 'SUB MAIN WHERE WE ENABLE VISUAL STYLES, AND RUN MAIN FORM
    2.     Public Shared Sub Main()
    3.         Application.EnableVisualStyles()
    4.         Application.DoEvents()
    5.         Application.Run(New frmMain)
    6.         Application.Exit()
    7.     End Sub


    It also requires you set the buttons flatstyle property to system instead of standard. (any control that has a flatstyle property should be set to system to render it in XP theme).

    .NET 2005 supports XP theme right from the get go, without needing to call this.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  5. #5
    New Member
    Join Date
    Sep 2006
    Posts
    8

    Re: Download Files From Web With Progressbar

    how can i add download time estimation to this code ? i'm a beginner please help me

  6. #6
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Download Files From Web With Progressbar

    Kleinma,

    Thanks again, I remember you helping me with this problem on an earlier date. I do have a quesition though, of course. How does this handle proxy servers or does it? If not how should I go about implementing that functionality?

    Thanks,

    Christian
    In life you can be sure of only two things... death and taxes. I'll take death.

  7. #7

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    It currently doesn't and I don't have a proxy server to test any code against.

    However I would imagine it would probably be as simple as setting the proxy property of the WebRequest object in the DownloadFileWithProgress routine.

    After the line

    wRemote = WebRequest.Create(URL)

    try adding

    wRemote.Proxy = new WebProxy()

    but specify the needed information in one of the WebProxy overloaded constructors.

    That should be all there is to it.

    Let me know how you make out.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  8. #8
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Download Files From Web With Progressbar

    Will do thanks.
    In life you can be sure of only two things... death and taxes. I'll take death.

  9. #9
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Download Files From Web With Progressbar

    Hi, I tried adding this to program to auto update and noticed that WebFileDownloader doesn't seem to work. I use VS 2005 and it says:
    Code:
    'Type 'WebFileDownloader' is not defined'

  10. #10

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    did you actually add the WebFileDownloader.vb class file to your project?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  11. #11
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Download Files From Web With Progressbar

    O.O No I didn't. I never thought of that. Sorry, I'm new to .NET and don't understand some things yet.

  12. #12

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    No problem, but that is what you need to do. Once you add that class file to your project, you can access that class.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  13. #13
    New Member
    Join Date
    Feb 2007
    Posts
    1

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by RingOfFire
    Thank you for the sample project.

    I have a question: When the user clicks the close button (or exits application) during a download, download procedure keeps going on.

    I'd like to know how to add the following feature:

    When the application is stopped somehow
    (by user, by system or other failure)

    1. Stop the download process
    2. Delete the file that was downloaded partially
    Excellent class, I just used it for a small updater program, however i did notice one thing, the downloader does not stop when the form is closed. The application remains present in the taskmanager until the download completes.

    I was wondering is anyone had any insight on how to make the downloader stop. I've never really used any web/http classes before they aren't really my forte. Maybe some kind of cancel event or something could be raised? I'm not really sure where this would be coded though. And i guess we'd have to clean up the partial stream. I'm kinda tired right now as I'm posting this so my brains not working 100%.

    Maybe just adding a cancel event that changes a member variable blnCancel = True and modifying some of the loops to check that variable will work. Then raising the event when the form closes would work, might not be the cleanest but I'll try it after I wake up. If it works I'll repost modified code if that's ok.

    Another thing I noticed is that download speed seem to dramatically increase after the downloaded stream starts reporting its size in MB rather than KB on my cable modem. I would say on average of 3-5x the speed it takes to go from 0 to 1MB. Not sure why this might be.

    Anyway again, thanks for the class, saved me some time!

  14. #14

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    well generally you would not want to allow the form to be closed while downloading. However if you want to offer a cancel option, you could simply set a boolean variable in the downloader class to indicate you want to cancel the download. Then in the DownloadFileWithProgress routine, check this boolean value in the do loop, and drop out of it if infact the cancel var is set to true. You may also want to delete the semi downloaded file when this happens, and maybe even add a new event like "DownloadCancelled". I did try to add a pause feature in recently, but so far it is still a little buggy.

    Also I am not sure about what you say regarding the download speeds when the file is over 1MB downloaded. I don't notice any significant speed changes between 0-1 MB and then larger... How big are the files you are downloading?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  15. #15
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    well generally you would not want to allow the form to be closed while downloading. However if you want to offer a cancel option, you could simply set a boolean variable in the downloader class to indicate you want to cancel the download. Then in the DownloadFileWithProgress routine, check this boolean value in the do loop, and drop out of it if infact the cancel var is set to true. You may also want to delete the semi downloaded file when this happens, and maybe even add a new event like "DownloadCancelled". I did try to add a pause feature in recently, but so far it is still a little buggy.

    Also I am not sure about what you say regarding the download speeds when the file is over 1MB downloaded. I don't notice any significant speed changes between 0-1 MB and then larger... How big are the files you are downloading?
    I am also noticing this, just reported it in another topic. It goes from 60 kbps to 700 kbps after it switches to MB. Maybe there is a way to keep it at MB from the beginning? (file=3mb).

  16. #16

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    are you sure it isn't just that it appears to be slower?

    Remember the progress will look a lot faster when its just showing kilobytes downloaded versus megabytes...

    The reason I say this, is because when progress of the download gets reported, its only in bytes, not in KB or MB.

    The number of bytes is passed to the shared FormatFileSize method, which returns the correct display string (ie kb, mb, etc..)

    so why don't you try NOT using the FormatFileSize, and see if you notice slowdown, I sure don't.

    If you are using my exact sample project, in the _Downloader.AmountDownloadedChanged event, comment the line

    Code:
    lblProgress.Text = WebFileDownloader.FormatFileSize(iNewProgress) & " of " & WebFileDownloader.FormatFileSize(ProgBar.Maximum) & " downloaded"
    and add the line

    Code:
    lblProgress.Text = iNewProgress.ToString & " of " & ProgBar.Maximum.ToString & " downloaded"
    this will make the label only report the bytes download, and not format them into MB, KB, etc.. for display purposes. Again I think you are just thinking it looks faster before it has DLed a MB of the file.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  17. #17
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: Download Files From Web With Progressbar

    Yes I am sure because I use an external program to measure download speeds (DU meter 3.07). Thats how I noticed the increase from 60 KB/s to 700 KB/s.

    I'll try the code, do I need to replace the first line you gave?

    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

  18. #18
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: Download Files From Web With Progressbar

    Ok I replaced the line, now it's slow all the way. I think updating for every byte might be a little to much for the app. Now I reached 61-117 KBps, my maximum speed (of the same file) is 1058 KB/s. Do you know the line to format in MB instead of autoformat?
    edit: when I remove the line entirely I get speeds from 640 - 890. Then the problem is solved... so the byte reporting is causing it to slow down.

    edit2:

    This also works (1 MB/s):
    Code:
    lblProgress.Text = "Bestandsgrootte: " & WebFileDownloader.FormatFileSize(Progbar.Maximum)
    Last edited by sdk1985; May 1st, 2007 at 04:24 PM.

  19. #19

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    well that is very common no matter what...

    any UI updating ALWAYS slows an app down...

    if you run a tight loop that scanned every file on your computer, it would run a bunch faster than if the same loop was also updating a label with the current file it was scanning.

    If you still want to show UI progress, but speed it up, you could use some sort of if statement to determine if you should update the GUI with progress or not. Since the default is to update after even chunk of the download is completed, perhaps only have it update 1 out of every 4 times the event fires or something.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  20. #20
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    well that is very common no matter what...

    any UI updating ALWAYS slows an app down...

    if you run a tight loop that scanned every file on your computer, it would run a bunch faster than if the same loop was also updating a label with the current file it was scanning.

    If you still want to show UI progress, but speed it up, you could use some sort of if statement to determine if you should update the GUI with progress or not. Since the default is to update after even chunk of the download is completed, perhaps only have it update 1 out of every 4 times the event fires or something.
    Ok but it is still weird that if it switches from bytes/kb to MB then after that it's fine... Maybe because the mb figures have to change less often?

    I'm new to vb 2005, thought the format was included in vb 2005. I see that you created it yourself.
    So I started editing, just doing this:
    Code:
    Else
                    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"
                    End Select
    Solves the slowdown for me. (I commented the kb case).
    Last edited by sdk1985; May 1st, 2007 at 04:41 PM. Reason: found solution

  21. #21
    Junior Member RingOfFire's Avatar
    Join Date
    May 2006
    Location
    Istanbul
    Posts
    28

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    well generally you would not want to allow the form to be closed while downloading. However if you want to offer a cancel option, you could simply set a boolean variable in the downloader class to indicate you want to cancel the download. Then in the DownloadFileWithProgress routine, check this boolean value in the do loop, and drop out of it if infact the cancel var is set to true. You may also want to delete the semi downloaded file when this happens, and maybe even add a new event like "DownloadCancelled". I did try to add a pause feature in recently, but so far it is still a little buggy.

    (...)
    As I'm a new coder: can you help me a bit more to include this code to my project? Maybe you can give some more clues, so that I can learn at the same time.

    Steps (according to what you've mentioned):
    1. Setting a boolean class for cancelling download
    2. Include this class within the DownloadFileWithProgress routine (inside do loop)
    3. Add DownloadCancelled event for erasing partially downloaded file or other stuff on "post partial-download event".

    Thanks a lot!
    Vista Error #01: Insufficient money spent in hardware.

  22. #22
    Addicted Member
    Join Date
    Apr 2007
    Posts
    174

    Re: Download Files From Web With Progressbar

    Hi Kleinma,
    thanks for the great code,
    I tried to adapt it to my case however I ran into an issue.
    My links are asp type of links and they open a doc file in MS Word.
    So they have the "?" charachter in the URL.
    When I enter them on the app it's telling me that there are illegal charchters.
    Any idea how this can be fixed ?
    thanks
    Last edited by Zoroxeus; Jun 3rd, 2007 at 09:34 AM.

  23. #23
    Lively Member sameer spitfire's Avatar
    Join Date
    Nov 2001
    Location
    India
    Posts
    120

    Re: Download Files From Web With Progressbar

    I need to download the file from the site which ask for userid and password

    i use the following code to download the file( Without userid and password)

    Code:
    Dim wClient As New System.Net.WebClient
            Dim add As String = "http://203.199.49.90/XMLXX/CCnn/15KT/Pnn_001.zip"
            Try
    
    download:
                wClient.DownloadFile(add, "n:\genbas\Pnn_011.zip")
    But how i can pass the userid and passwords To the above string
    Plase help
    with Regards
    sameer Mulgaonkar

  24. #24
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Download Files From Web With Progressbar

    A simple way would be this:

    http://203.199.49.90/XMLXX/CCnn/15KT...serid=sam&pwd=[encrypted password here]
    In life you can be sure of only two things... death and taxes. I'll take death.

  25. #25

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by sameer spitfire
    I need to download the file from the site which ask for userid and password

    i use the following code to download the file( Without userid and password)

    Code:
    Dim wClient As New System.Net.WebClient
            Dim add As String = "http://203.199.49.90/XMLXX/CCnn/15KT/Pnn_001.zip"
            Try
    
    download:
                wClient.DownloadFile(add, "n:\genbas\Pnn_011.zip")
    But how i can pass the userid and passwords To the above string
    Plase help
    Specify the user id/password in the credentials property of the webclient before making the download call.

    Code:
            Dim wClient As New System.Net.WebClient
            Dim add As String = "http://203.199.49.90/XMLXX/CCnn/15KT/Pnn_001.zip"
            Try
                wClient.Credentials = New Net.NetworkCredential("userid", "password")
                wClient.DownloadFile(add, "n:\genbas\Pnn_011.zip")
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  26. #26
    Member
    Join Date
    Nov 2007
    Posts
    44

    Re: Download Files From Web With Progressbar

    Nice job but how can i make it auto-update when start and how can I let it automaticly extract the rar

  27. #27

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    Those questions are beyond the scope of what this example does. This example code is specifically just for downloading files with progress.

    You should really ask your questions in the main VB.NET forum.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  28. #28
    Member
    Join Date
    Nov 2007
    Posts
    44

    Re: Download Files From Web With Progressbar

    deleted
    Last edited by xSmurf; Nov 10th, 2007 at 01:57 PM.

  29. #29
    Addicted Member
    Join Date
    Jan 2008
    Posts
    154

    Re: Download Files From Web With Progressbar

    Nice sample but how can i add authentical for rapidshare.com. Thx

  30. #30

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by michalss
    Nice sample but how can i add authentical for rapidshare.com. Thx
    In the downloader class, in the routine called DownloadFileWithProgress you could add the following line of code:
    Code:
    wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
    this should go right after
    Code:
    wRemote = WebRequest.Create(URL)
    and before
    Code:
    Dim myWebResponse As WebResponse = wRemote.GetResponse
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  31. #31
    Addicted Member
    Join Date
    Jan 2008
    Posts
    154

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    In the downloader class, in the routine called DownloadFileWithProgress you could add the following line of code:
    Code:
    wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
    this should go right after
    Code:
    wRemote = WebRequest.Create(URL)
    and before
    Code:
    Dim myWebResponse As WebResponse = wRemote.GetResponse

    Im sorry for my question but can you give me more info or simple exaple appl. Thx i will be more then greatfull...

    EDIT : I Have Try your exaple and i was add this syntaxe but it did not work...
    Last edited by michalss; Jan 9th, 2008 at 09:52 AM.

  32. #32

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    what more do you need?

    1) download and open up the my example code
    2) go into the class file called WebFileDownloader
    3) find the routine called DownloadFileWithProgress
    4) find the line of code mentioned above
    wRemote = WebRequest.Create(URL)
    5) insert this code after it
    wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
    6) change USERNAME and PASSWORD to actual valid values
    7) test code against site that needs authentication
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  33. #33
    Addicted Member
    Join Date
    Jan 2008
    Posts
    154

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    what more do you need?

    1) download and open up the my example code
    2) go into the class file called WebFileDownloader
    3) find the routine called DownloadFileWithProgress
    4) find the line of code mentioned above
    wRemote = WebRequest.Create(URL)
    5) insert this code after it
    wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
    6) change USERNAME and PASSWORD to actual valid values
    7) test code against site that needs authentication

    Its not working i have try it just now

    Code:
      FS = New FileStream(Location, FileMode.Create, FileAccess.Write)
                wRemote = WebRequest.Create(URL)
                wRemote.Credentials = New Net.NetworkCredential("myname", "mypass")
                Dim myWebResponse As WebResponse = wRemote.GetResponse
                RaiseEvent FileDownloadSizeObtained(myWebResponse.ContentLength)
                Dim sChunks As Stream = myWebResponse.GetResponseStream
                Do
                    iBytesRead = sChunks.Read(bBuffer, 0, 256)
                    FS.Write(bBuffer, 0, iBytesRead)
                    iTotalBytesRead += iBytesRead
                    If myWebResponse.ContentLength < iTotalBytesRead Then
                        RaiseEvent AmountDownloadedChanged(myWebResponse.ContentLength)
                    Else
    Can you check it for me pls?

    EDIT : Its download only 5 Kb from 100 MB....

  34. #34

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    they might be doing some sort of redirect on the server, so you may only be getting the first response.

    I dont know how rapidshare servers work and if they just serve out the file when you navigate to it, or do some sort of redirect. Chances are if you are getting 5KB, its HTML.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  35. #35
    Addicted Member
    Join Date
    Jan 2008
    Posts
    154

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    they might be doing some sort of redirect on the server, so you may only be getting the first response.

    I dont know how rapidshare servers work and if they just serve out the file when you navigate to it, or do some sort of redirect. Chances are if you are getting 5KB, its HTML.
    Thx for quick response : I have try download http://rs201.rapidshare.com/files/82...9.0.0e-DVT.rar

    How ever is any chance to get close have a look on this problem pls? Im really desperate to get it work. Im looking for solution almoust 2 months. I can also pay for your time if is it reuquire.... Thx

  36. #36

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    do you have a premium acct for rapidshare?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  37. #37
    Addicted Member
    Join Date
    Jan 2008
    Posts
    154

    Re: Download Files From Web With Progressbar

    Quote Originally Posted by kleinma
    do you have a premium acct for rapidshare?

    Yes i have 2 if you need ...

  38. #38

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    well just by looking at the site, they defenitly do some funky redirects (at least when u use the free downloading service). They might even do direct response writing of the files to prevent people from direct linking.

    If you want to PM me one of your acct id/passwords, I will test trying to make it work, as it may be easier when you have an actual paid acct to work with. I can't promise I will be able to get back to you right away, but if you PM me with that info, I will look at it when I have a few free minutes.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  39. #39
    New Member
    Join Date
    Mar 2008
    Location
    SE Asia
    Posts
    6

    Resolved Re: Download Files From Web With Progressbar

    Here is a link to an article from Karl Moore, that can determine if a connection to the internet is available.

    http://www.developerfusion.co.uk/show/3903/

  40. #40

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,272

    Re: Download Files From Web With Progressbar

    That code from Karl will actually error.. it should be written like this:

    Code:
        Public Function IsConnectionAvailable() As Boolean
            ' Returns True if connection is available 
            ' Replace www.yoursite.com with a site that
            ' is guaranteed to be online - perhaps your 
            ' corporate site, or microsoft.com
            Dim objUrl As New System.Uri("http://www.yoursite.com/")
            ' Setup WebRequest
            Dim objWebReq As System.Net.WebRequest = Nothing
            objWebReq = System.Net.WebRequest.Create(objUrl)
            Dim objResp As System.Net.WebResponse = Nothing
            Try
                ' Attempt to get response and return True
                objResp = objWebReq.GetResponse
                objResp.Close()
                objWebReq = Nothing
                Return True
            Catch ex As Exception
                ' Error, exit and return False
                If objResp IsNot Nothing Then
                    objResp.Close()
                    objWebReq = Nothing
                    Return False
                End If
            End Try
        End Function
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

Page 1 of 4 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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.