Solved

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

Posted on 2006-11-01
10
5,241 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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