Solved

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

Posted on 2006-11-01
10
5,230 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

14 Experts available now in Live!

Get 1:1 Help Now