Results 1 to 8 of 8

Thread: Can u do a silent download with the WebBrowser1 Object

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    124

    Can u do a silent download with the WebBrowser1 Object

    Can u do a silent download with the WebBrowser1 Object
    When u navigate to a zip file, is asks you if you want to save it and to where

    Is there a way to automate that

    is there a way to know when a download of a zip file is complete can be detected by the WebBrowser objects

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Can u do a silent download with the WebBrowser1 Object

    Is there any chance of someone answering this question?
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Can u do a silent download with the WebBrowser1 Object

    There is an API that you can use (not associated with WebBrowser). I think it's something like URLDownload but not sure. As far as using WebBrowser for a silent download I have seen some examples around here from time to time but quite frankly I don't think they really work.

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Can u do a silent download with the WebBrowser1 Object

    All that I have looked at has been of no use to me, although I have found out that the "FileDownload" event is fired in a webbrowser before it shows a dialog box, so that is going to be the obvious way of doing it if it is possible.

    However, I need the WEBBROWSER itself to do the downloading rather than outsourcing the download to another method. If URLDownload uses webbrowser then it may be capable of doing what I need (I am trying to automate downloading of a file which requires references and such in the headers so unless I write a custom winsock routine, which I am useless at, I have to do it in webbrowser :-))
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  5. #5
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Can u do a silent download with the WebBrowser1 Object

    Joacim posted a working solution in http://www.vbforums.com/showthread.php?t=85378 but it is not a total solution...doesn't work for what I need it, and just refuses to fire before the dialog pops up
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  6. #6
    Member
    Join Date
    Mar 2008
    Posts
    55

    Re: Can u do a silent download with the WebBrowser1 Object

    i found this code, thanks to the original coder.

    Put this in your form.
    Code:
    Private Sub Command1_Click()
    
    Call DownloadFile(MyURL, MyLocalFile) ' Downloads..
    
    ' Opens the source onto the screen. Optional
    On Error Resume Next
    Open MyLocalFile For Input As #1
    HTMLSource = Input(LOF(1), 1)
    Close #1
    
    MsgBox "Download complete." & vbNewLine & vbNewLine & "To open your file, go here: " & MyLocalFile, vbInformation, "Downloaded"
    
    
    End Sub
    Create A Module and put this in.
    Code:
    Public Declare Function URLDownloadToFile Lib "urlmon" Alias _
    "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
    szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    
    Sub DownloadFile(URL As String, SaveAsFile As String)
    Dim b
    b = URLDownloadToFile(0, URL, SaveAsFile, 0, 0)
    End Sub

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Can u do a silent download with the WebBrowser1 Object

    Here is one way that I use but it only works for downloading a file from a link (for example, <a href="http://www.somewebsite.com/somefile">Click here to download</a>).

    If what you want to download is like in a button you might be able to figure out some way to capture that method.
    Code:
     
    Private DownloadFileName As String
    Private DownloadThisItem As Boolean
    
    Private Sub Command1_Click()
     WebBrowser1.Navigate the-website-url
    End Sub
    
    Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
     On Error GoTo ExitSub
     
     If DownloadThisItem = True Then
       Label1.Caption = "This File Will Be Downloaded: " & DownloadFileName
       Cancel = True
       '
       ' Do something to download the file - like call the API 
       '
     End If
    ExitSub:
    End Sub
    
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
     If InStr(Text, "http://") > 0 Then
       DownloadThisItem = True
       DownloadFileName = Text
       Label1.Caption = "Download File Link = " & DownloadFileName
     Else
       DownloadThisItem = False
       DownloadFileName = ""
       Label1.Caption = ""
     End If
    End Sub

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Can u do a silent download with the WebBrowser1 Object

    Just a note on my above post. It is very limited and I whiped it up for only to use on known links that are for downloading. It is not 100%. It has some drawbacks which I didn't work out at the time I posted it and one is that if you click on a link that is not a download it will still think it is so that would have to be worked out to get around that problem. I'm sure there is a better way but at that time I wasn't giving too much thought to it so I just posted that quicky method.

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