Solved

Vb.Net - Copy an image from a URL to a specific path ???

Posted on 2006-11-01
10
5,237 Views
Last Modified: 2008-03-10
Hi everyone,

I need your help.

I'm writing a Vb.Net application which should copy many images (images001.jpg, images002.jpg...) from an URL address (i.e http://mysite.com/images/images001.jpg).

I don't know how to copy each image from the URL address (i.e http://mysite.com/images/) to a network path (i.e \\MyNetwork\Images\).

I had already found on internet a code which allow me to check the existence of any image giving a URL address.

Can anyone tell me how to copy an image from a URL to a specific path ?

Thank you.

Paul


    Function ImageExiste(ByVal p_url As String) As Boolean

        Dim xmlHttp
        xmlHttp = CreateObject("Microsoft.xmlHttp")
        xmlHttp.Open("GET", p_url, False)
        xmlHttp.Send()

        Select Case xmlHttp.status

            Case 200 'found
                ImageExiste = True

            Case 404 'Not found
                ImageExiste = False

            Case Else 'Some other problem
                ImageExiste = False

        End Select

        'ImageExiste = xmlHttp.Status
        xmlHttp = Nothing

    End Function



0
Comment
Question by:paulnamroud
10 Comments
 
LVL 10

Expert Comment

by:gangwisch
ID: 17852470
Dim w As New WebClient
        w.DownloadFile(address, filename)
0
 

Author Comment

by:paulnamroud
ID: 17852545
Sorry, but it didn't work the method you gave me ...
0
 
LVL 6

Accepted Solution

by:
dave_moats earned 125 total points
ID: 17852877
You should be able to expand this sample to allow you to download multiple files.

This downloads the file specified by srcPath to outPath.

The imports:

    Imports System
    Imports System.Net


The sub:

    Sub getFile()

        'Address of URL
        Dim srcPath As String = <URL to Your Image>
        Dim outPath As String = <Name to Save Image As>

        Dim client As WebClient = New WebClient

        client.DownloadFile(srcPath, outPath)

    End Sub


Dave
0
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.

 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 125 total points
ID: 17854432
paulnamroud here's another way wrapped up in a proc:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetImage("http://mysite.com/fs_img/mysite/0506/logo.gif", "C:\Logo.gif")
    End Sub

    Private Sub GetImage(ByVal URL As String, ByVal SaveAs As String)
        Try
            Dim srv_request As System.Net.WebRequest = System.Net.WebRequest.Create(URL)
            Dim srv_response As System.Net.WebResponse = srv_request.GetResponse()
            Dim ImgStream As IO.Stream

            ImgStream = srv_response.GetResponseStream()
            System.Drawing.Image.FromStream(ImgStream).Save(SaveAs)
        Catch
        End Try
    End Sub
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18035246
I think the points should be split between myself and dave_moats.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 18035993
I think Kinger's suggestion is valid as both solutions can be used to answer the question.
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18083490
I agree.
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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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