How to Save Bitmap from MS Internet Controls Webbrowser control

I am using VB6.0 sp5 and have managed to create a form with the webbrowser control which displays web content ok.  What I want to be able to do is to go round a loop of web addresses and saving the returned png or bmp files to my hard drive, changing their names to include the date.  The urls point directly at the images so there is nothing else on the page to worry about.  I see there is a webbrowser.document object but when I click '.' no other objects are displayed.  Can someone more familiar indicate if there is a FileSave or similar method please?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, barnesd1.  Per this EE post:

Do the following:

1) Create a folder to hold your images (below uses "C:\Images\").

2) In the General Declarations put:

Private 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

Const SaveTo As String = "C:\Images\"

3) In your userform add the DownloadFile and Download Functions.

Since we want to add the date to the image name, we need to modify the DownloadFile function as follows:

Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim myRight As String, myDate As String
    myDate = Date
    myDate = Replace(myDate, "/", "")
    myRight = Right(URL, InStr(1, StrReverse(URL), "/") - 1)
    LocalFilename = Replace(LocalFilename, myRight, "")
    LocalFilename = LocalFilename & myDate & myRight
    Dim lngRetVal As Long: lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function

4) In your WebBrowser's DocumentComplete method add (presuming your WB is named "WebBrowser1"):
     Download WebBrowser1.LocationURL

If you didn't mind getting a popup box, you could forego all of the above and place the following in your WebBrowser's DocumentComplete method:


You would then manually input the date in the Save As textbox.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
barnesd1Author Commented:
Thanks for this.  The code does save the file.  The problem is that before it gets the DownloadFile code it prompts the user with "Some files can harm your computer..." and asks for Open, Save, Cancel or More Info buttons to be pressed.  If I press Cancel then the DownloadFile codes runs ok.  I'm accessing the internet through a network proxy by the way.  Any ideas?
barnesd1Author Commented:
I had to resort to the slightly embarrassing Sendkeys "{esc}" to avoid the dialog but this seems reliable enough for the 8 daily urls I need to go to and save to disk.
Sorry for not getting back earlier; have been on vacation since 7/1 with no access to email or VB 6. I wonder if using WebBrowser1.Silent = True would handle the pop-up (when using steps 1-4 above)? Or going to IE's top menu, Tools/Internet Options/Security and adjusting the settings?
barnesd1Author Commented:
Silent = True didn't help and I have no access to change my security settings as they are locked down.  Thanks anyway.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.