|
-
Jun 26th, 2001, 03:18 AM
#1
Thread Starter
Addicted Member
trying to get around the "File Download" dialog box in internet explorer
When you click on a file in internet explorer (file.exe for example) then the "File Download" dialog box comes up. I have a webbrowser control in my program, and when people click on "file.exe" then I don't want the "file download" dialog to appear, I just want it to automatically download to the desktop. An input box that says "Are you sure you want to download 'file.exe'?" would be better, but If you tell me the first thing then I can add the inputbox after.
Thanks in advance.
-
Jun 26th, 2001, 05:58 AM
#2
You can combine the URLDownloadToFile API with the FileDownload event.
You must remeber the last URL though, save it in a variable in the BeforeNavigate2 event.
Code:
Private Declare Function URLDownloadToFile _
Lib "urlmon.dll" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal lpfnCB As Long) As Long
Private sUrl As String
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)
sUrl = URL
End Sub
Private Sub WebBrowser1_FileDownload(Cancel As Boolean)
Dim sFileName As String
Cancel = True
sFileName = Mid$(sUrl, InStrRev(sUrl, "/") + 1)
'change the following to the folder you
'want to save the file to
sFileName = "c:\" & sFileName
If MsgBox("Are you sure you want to download this?", _
vbQuestion + vbYesNo) = vbYes Then
URLDownloadToFile 0, sUrl, sFileName, 0
End If
End Sub
Best regards
-
Jun 26th, 2001, 05:58 PM
#3
Thread Starter
Addicted Member
I used this exact code:
--------------------------------------------------------------------------------
Private Declare Function URLDownloadToFile _
Lib "urlmon.dll" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal lpfnCB As Long) As Long
Private sUrl As String
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)
sUrl = URL
End Sub
Private Sub WebBrowser1_FileDownload(Cancel As Boolean)
Dim sFileName As String
Cancel = True
sFileName = Mid$(sUrl, InStrRev(sUrl, "/") + 1)
'change the following to the folder you
'want to save the file to
If MsgBox("Are you sure you want to download this?", _
vbQuestion + vbYesNo) = vbYes Then
URLDownloadToFile 0, sUrl, "c:\" & sFileName, 0
End If
End Sub
--------------------------------------------------------------------------------
The msgbox comes up and asks.. and I hit yes.. but then I go check c:\ and there are no files there. Can somebody tell me whats wrong with the code?
-
Sep 1st, 2005, 04:08 PM
#4
New Member
Re: trying to get around the "File Download" dialog box in internet explorer
I copied the code above and the event filedownload dosen't fire
what's wrong???
-
Sep 1st, 2005, 04:46 PM
#5
Re: trying to get around the "File Download" dialog box in internet explorer
-
Jul 6th, 2006, 01:49 PM
#6
Addicted Member
Re: trying to get around the "File Download" dialog box in internet explorer
VB Code:
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
Private Sub Form_Load()
DoFileDownload StrConv("http://www.server.com/download/file.zip", vbUnicode)
End Sub
-
Jul 6th, 2006, 02:03 PM
#7
Re: trying to get around the "File Download" dialog box in internet explorer
@foxter: You are aware that this thread was 5 years old, aren't you?
-
Jul 6th, 2006, 05:04 PM
#8
Addicted Member
Re: trying to get around the "File Download" dialog box in internet explorer
People dont [RESOLVE] the thread, and dont post the answer they got. How do you think other people will get the answer? Do others need to ask again the same question? I'd rather post the solution, so others would have it, no matter how old the problem is.
-
Jul 6th, 2006, 05:23 PM
#9
Re: trying to get around the "File Download" dialog box in internet explorer
Well, 5 years ago it wasn't as common for people here to put the word "RESOLVED" in the title. Besides, using DoFileDownload as you suggested does not "get around the 'File Download' dialog box" which was the origional question. Using URLDownloadToFile as I suggested in post #2 above (5 years ago) would however do that.
-
Sep 24th, 2008, 12:36 PM
#10
Re: trying to get around the "File Download" dialog box in internet explorer
Also, Cancel = True doesn't prevent the normal download dialog box from appearing. Don't even know what it's purpose is. However, the code for something like this should be placed in the _BeforeNavigate2 event because there Cancel = True will prevent the download box from popping up.
Last edited by jmsrickland; Sep 24th, 2008 at 02:00 PM.
-
Sep 24th, 2008, 02:30 PM
#11
Re: trying to get around the "File Download" dialog box in internet explorer
This will bypass the dialog box:
Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)
Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.
OnResponseStart when you can safely access the headers.
OnResponseDataAvailable which returns a byte array of downloaded data for each chunk.
OnResponseEnd which ends the download.
Code:
Option Explicit
Private WithEvents http As WinHttpRequest
Private mContentLength As Long
Private mProgress As Long
Private Sub Command1_Click()
' Create the WinHTTPRequest ActiveX Object.
Set http = New WinHttpRequest
' Open an HTTP connection.
http.open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg", True 'True means asynch.
' Send the HTTP Request.
http.send
End Sub
Private Sub http_OnResponseDataAvailable(Data() As Byte)
mProgress = mProgress + UBound(Data) + 1
ProgressBar1.Value = mProgress
Put #1, , Data
End Sub
Private Sub http_OnResponseFinished()
Close #1
MsgBox "done"
End Sub
Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
Text1.Text = http.getAllResponseHeaders()
mProgress = 0
mContentLength = CLng(http.getResponseHeader("Content-Length"))
ProgressBar1.Max = mContentLength
Open "C:\twg_gdo_1.mpg" For Binary As #1
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Sep 24th, 2008, 03:53 PM
#12
Re: trying to get around the "File Download" dialog box in internet explorer
This will bypass the dialog box:
What dialog box are you refering to?
-
Sep 24th, 2008, 03:57 PM
#13
Re: trying to get around the "File Download" dialog box in internet explorer
 Originally Posted by jmsrickland
This will bypass the dialog box:
What dialog box are you refering to?
The ie download dialog
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|