Solved

getting an image from a web site

Posted on 2002-05-06
5
126 Views
Last Modified: 2010-05-02
Hi,
 I know the url and name of an image that sits on a web site. I would like click a button on a VB form to automatically go to the URL and get the image to place on a directory on my machine. Of course, I can always do this manually by opening IE, navigating the the web site, right-clicking on the image, and "Save Target As". But how can I automate this in VB?

  1) Add a browser control to a Form?
  2) Tell the browser control to open a certain url
  3) ????? download the image ????? how??

The third step is where I need help.
Real working source code will get you the points.
TIA
DoughBoy
0
Comment
Question by:DoughBoy
  • 2
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 6992073
You can use a quick and easy API function:

"HOWTO: Download a File Without Prompting (Q244757)"
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q244757
0
 

Author Comment

by:DoughBoy
ID: 6992105
good job!!
next time, I will learn to search the MS site myself.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6992159
reference microsoft internet transfer control and microsoft internet controls

put a webbrowser control on form and an inet control:

then do:
Private Sub Command1_Click()
'    On Error Resume Next
   
    WebBrowser1.Navigate "http://www.prototrack.com"
    While WebBrowser1.Busy
        DoEvents
    Wend
   
    Dim strImageSrc As String
    Dim bData() As Byte
   
    Screen.MousePointer = vbHourglass
    For i = 0 To WebBrowser1.Document.images.length
        strImageSrc = WebBrowser1.Document.images(i).src
   
        '' call your download routine here
        bData = Inet1.OpenURL(strImageSrc, icByteArray)
               
        '' get the file name to write to
        strSaveFile = Split(strImageSrc, "/")
       
        '' write the byte stream to disk
        MsgBox strSaveFile(UBound(strSaveFile))
        Open App.Path & "\" & strSaveFile(UBound(strSaveFile)) For Binary Access Write As #1
        Put #1, , bData()
        Close #1

    Next
    Screen.MousePointer = vbDefault
End Sub
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6992162
damn, azra always get's the webbrowser control questions :(

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6992172
Lots of experience with it   :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now