Solved

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

Posted on 2006-11-01
10
5,248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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