How to display image on ASP from ADODB.Stream object

Hello,

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 ADODB.stream 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.Open
 adoStream.Type = 1
 FPath = "C:\images\1.png"
 adoStream.LoadFromFile FPath

 Response.BinaryWrite adoStream.Read 

 adoStream.Close
 Set adoStream = Nothing 
 Response.End
 %>

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.
ZKM128Asked:
Who is Participating?
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 MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Why not just create a virtual directory in IIS? Is that an option?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
If you must stream them have a look at this article:

http://www.chilkatsoft.com/p/p_271.asp
0
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?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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

http://www.chilkatsoft.com/p/p_271.asp

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.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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:

https://technet.microsoft.com/en-us/library/cc771804%28v=ws.10%29.aspx

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
0
Dave BaldwinFixer of ProblemsCommented:
This works.

ReadImage.asp
<%
' from http://support.microsoft.com/kb/276488
'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.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
%>

Open in new window


ReadImage.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

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

Open in new window

0

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
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.