Popular Articles | Latest Articles | Categories | RSS Feeds

Image downloading from remote servers in ASP

Published on 5/22/2008 by Site Editor
More articles in ASP



 Vote this tutorial:

In this tutorial, we will access to a remote server, download image, rename ths image and save to our file system. We will use one function (getImage) and one subroutine (saveImage) to complete this sampel code.

First part of our code, get image byte array from remote server. Second part contains a subroutine that writes byte array to file system.

Lets's put our function and subroutine calls in the beginning of code.

Creating variables

imageUrl = "htp://www.some-domain-name.com/images/target-image.jpg"
strImageName = "new-image.jpg"

 

Function and subroutine calls

saveImage getImage(imageUrl), strImageName


Here is code library:

Function getImage(strImageUrl)
' Set objHttp = CreateObject("Microsoft.XMLHTTP")
' Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
Set objHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
' Set Http = CreateObject("WinHttp.WinHttpRequest")
objHttp.Open "GET", URL, False
objHttp.Send

getImage = getImageHttp.ResponseBody
End Function

Sub saveImage(ByteArray, strImageName)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1

Set objBinaryStream = CreateObject("ADODB.Stream")
objBinaryStream.Type = adTypeBinary

objBinaryStream.Open
objBinaryStream.Write ByteArray
objBinaryStream.SaveToFile "C:\Inetpub\wwwroot\dotnetindex.com\images\" & (strImageName), adSaveCreateOverWrite
response.Write("Image has been download and saved!")
end sub

 

Aim of this article, to be a reference how to download bytes from remote servers. You may use this source code after adding some error controlling to sample code.

Happy Coding

This part of code creates two main variables: imageUrl and strImageName.

Comments:
no comments submitted


Only members can write comments.Please, login / register to write comment.

Latest Posts

    Active News Manager - news management system




    Welcome to Dotnetindex.com:Login  |  Register
    Free software:
    Giga RSS Reader
    IkonAdman
    QMailing list
    Active News
    Download Manager (PRO)
    Download Manager (Lite)

    Search Dotnetindex.com:


    Who's online

    • There 16 online users.

    Latest tutorialsAutocomplete Filter from the Old Futures Project Working in Dynamic Data 4
    Developing a Facebook Connect Application Using ASP.NET
    Conditional Row Highlighting in Dynamic Data
    UserControl as a DLL Made Easy
    Using GroupTemplate in ASP.NET ListView Control (Tiled Display)
    Creating Master-Detail GridView Using jQuery
    ASP.NET MVC 2.0 and AJAX Part 1
    Sorting Tabular Data in ASP.NET MVC
    Asynchronous Form in ASP.NET MVC 2
    Populating ASP.NET TreeView Control Recursively
    A look at SAP Crystal Reports for Visual Studio 2010
    Reporting in Threads
    Regular Expressions Make Pattern Matching and Data Extraction Easier
    Perform Database Administration Operations with SQL Server Management Objects
    SQL Server Compact 3.5 Beta 2 available for download
    ASP.NET Resources, Reviews

    ASP Resources, Reviews

    PHP, ASP, .NET, JSP Resources, Reviews

    Hotscripts.com Free Photoshop, Flash and 3DS MAX tutorials