Solved

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

Posted on 2006-11-01
10
5,250 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

636 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