View Full Version : Control IE download dialog?


bionicman
12-18-2007, 12:56 PM
I am working on a database that will go to a website and download a specific file each day. So far i have everything worked out except the download dialog. I can navigate to the website, tell it which file to download and then i am prompted with the download dialog box.

Is there anyway to automate this and tell IE where to automatically download the file to without prompting?

Thank You!

ByteMyzer
12-18-2007, 08:21 PM
The following function will download a file from a specified URL and save it to the specified FilePath:

Public Function SaveHTTPFile( _
ByVal sUrl As String, _
ByRef sFilePath As String)

Dim byteData() As Byte
Dim ff As Integer
Dim XMLHTTP As Object

Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")

XMLHTTP.Open "GET", sUrl, False
XMLHTTP.send
byteData = XMLHTTP.responseBody

Set XMLHTTP = Nothing

ff = FreeFile
Open sFilePath For Binary Access Write As #ff
Put #ff, , byteData
Close #ff

End Function


Example:
SaveHTTPFile "http://www.mysite.com/myfile.txt", "C:\MyFolder\myfile.txt"

bionicman
12-19-2007, 05:32 AM
Thanks for the reply and the code, i will hang on to this for future use, but unfortunatly it doesn't work for my current needs because of the way the website is setup.

After i log in to the website, i am presented with a list of available files, each of which has a form button to download the appropriate file. They use cgi, so the link attached to the button is something like this


download.exe?page=DCFILES&area=DC%20834%5cDatasets%5cDC%5f071218%5f20934%5f7 9637%5f57220%5f834%2e001


I can send that link to my browser and it prompts the file download, but that is what i need to automate. I tried sending that link in your code, but it didn't work.

Is there anyway to take your existing code and modify it for this?

Thank You!

ByteMyzer
12-19-2007, 07:24 AM
Have you tried passing the entire URL?


Example:

http://www.mywebsite.com/download.exe?page=DCFILES&area=DC%20834%5cDatasets%5cDC%5f071218%5f20934%5f7 9637%5f57220%5f834%2e001

bionicman
12-19-2007, 10:39 AM
Yeah, that is what i do, and it works fine, i am presented with the download dialog, but i was hoping i could automate it so the user won't have to save it to a certain location each day.

ByteMyzer
12-19-2007, 11:28 AM
I meant, have you tried using my code, passing the entire URL as the parameter?

Example:

SaveHTTPFile "http://www.mywebsite.com/download.exe?page=DCFILES&area=DC%20834%5cDatasets%5cDC%5f071218%5f20934%5f7 9637%5f57220%5f834%2e001", _
"C:\MyFolder\myfile.txt"


The SaveHTTPFile function transmits the specified URL information, retrieves the response and saves the data to the filepath you specify, without the prompting dialog box.

Perhaps if you were to send me a Private Message with the specific URL information and file path information, I can test it and let you know the best way to use the function to accomplish your requirement.