How to display image on ASP from ADODB.Stream object


I need to show images on my ASP. Due to the security reasons, I cannot simply put all of my images in the images folder in my website folder and I need to put them outside of my website folder.
For example, my website folder is located at: C:\Inetpub\wwwroot\mysite\
But I need to put images (which I want to show on my web pages) at: C:\images\

I am trying to use object to pull the images from C:\Images folder and display the image on my ASP using ASP vb codes as shown below

Name of this ASP: ReadImage.asp
 Response.ContentType = "image/png"
 Set adoStream = Server.CreateObject("ADODB.Stream") 
 adoStream.Type = 1
 FPath = "C:\images\1.png"
 adoStream.LoadFromFile FPath

 Response.BinaryWrite adoStream.Read 

 Set adoStream = Nothing 

Open in new window

When I launch this webpage in internet explorer, the page shows a File Download window/message for downloading the image file "1.png" rather than displaying the image on the web page.

 I also tried creating another ASP named "DisplayImage.asp" and used the following code to display the image on this page but,

 <img src="ReadImage.asp">

Open in new window

 when I launch this page, the page cannot display the image either.

 Please explain how to change this code to make it work.

 Thank you.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
Why not just create a virtual directory in IIS? Is that an option?
Big MontyWeb Ninja at largeCommented:
If you must stream them have a look at this article:
ZKM128Author Commented:
I don't know how to do this by creating virtual directory. Could you please explain to me in detail how to do it by using virtual directory in IIS?
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

ZKM128Author Commented:
Thanks for your help but the example at:

doesn't seem to explain how to display the image file on the web page (html or asp) but just explains how to stream and download files.
Big MontyWeb Ninja at largeCommented:
Virtual directories are folders you can map to in your site without them actually residing in your site structure. For example, you can map c::\folder to your site which lies in c:\inetpub\www\mysite\ and you would then be able to access it like a sub folder off of your site.

Here's a good article on how to set up a virtual folder:

Once you set it up, copy your files to the folder (if they're not already there) and use the img tag like:

 <img src="/images/ReadImage.asp">

This example assumes your folder is named images. if you have any further questions feel free to ask
Dave BaldwinFixer of ProblemsCommented:
This works.

' from
'Set the content type to the specific type that you are sending.
Response.ContentType = "image/png"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "C:\images\1.png" 'This is the path to the file on disk. 

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.BinaryWrite objStream.Read

Set objStream = Nothing

Open in new window

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<title>ReadImage in ASP</title>
<h1>ReadImage in ASP</h1>
<img alt="" src="ReadImage.asp" />

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.