Want to work with us? We're on the lookout for digital experts.

We're hiring

Download and Save Image Using URL

Web Bureau

04 April 2011 by Web Bureau

If you need to download images across sites try using this function.

Public Function getImageByUrl(ByVal url As String, ByVal filename As String) As Boolean

        Dim response As WebResponse = Nothing
        Dim remoteStream As Stream = Nothing
        Dim readStream As StreamReader = Nothing
            Dim request As WebRequest = WebRequest.Create(url)
            If request IsNot Nothing Then
                response = request.GetResponse()
                If response IsNot Nothing Then
                    remoteStream = response.GetResponseStream()

                    readStream = New StreamReader(remoteStream)

                    Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(remoteStream)

                    If img Is Nothing Then
                        Return False
                    End If

                    img.Save(System.Web.HttpContext.Current.Server.MapPath("\databaseimages\") & filename, System.Drawing.Imaging.ImageFormat.Jpeg)
                End If
            End If
            If response IsNot Nothing Then
            End If
            If remoteStream IsNot Nothing Then
            End If
            If readStream IsNot Nothing Then
            End If
        End Try

        Return True
    End Function

Grow your businessStart a project with us today.

This site uses essential cookies for parts of the site to operate and have already been set. Find out more about how we use cookies and how you may delete them. You may delete cookies, but parts of the site will not work.