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
Re: Can u do a silent download with the WebBrowser1 Object
Is there any chance of someone answering this question?
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.
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 :-))
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
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
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
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.