Solved

getting an image from a web site

Posted on 2002-05-06
5
128 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 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