Click here to Skip to main content
13,087,902 members (70,401 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Everyone,

I have one HTML page, on submitting I am calling a Hanlder (ASHX).

In handler, I am generating an image. That image should not be saved on client/server machine. So I saved the Image in MemoryStream. After that I need to display that image with some detail text.

I could display the Image with Response.BinaryWrite() method.. but when I try to write text with Response.Write(), text does not appear.

Dim ms As MemoryStream = New MemoryStream()
BCImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
context.Response.ContentType = "image/jpeg"
context.Response.Write("<BR> HI <BR>")

Any ideas... !!
Posted 24-Oct-10 22:54pm
Sunasara Imdadhusen 25-Oct-10 5:38am
I think you should provide full privilege of folder
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

PS:This below code is in C#.
Please do the following steps to resolve it.

Step1: Take 1 new Page Test.aspx

Code behind Test1.aspx.cs
protected void Page_Load(object sender, EventArgs e)
System.Drawing.Image BCImage = new  System.Drawing.Bitmap(@"C:\test.jpg");
MemoryStream ms = new MemoryStream();
BCImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "image/jpeg";

Step2: On your handler page
Image img = new Image();
img.ImageUrl = "~/Test1.aspx";
Response.Write("<BR> HI <BR>");

Then it will show you both the things(Image and text/html content)

If this helped you then please Vote and accept as Answer :rose:
Sifar - 0 25-Oct-10 8:06am
It worked !!
I used as follow...

context.Response.Write("<img src=""Test1.aspx?PATH=path"" alt=""ASPX IMAGE"">")

Thank you....


@Everyone, if anyone knows how to achieve this without adding ASPX page then it would be really appreciated.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have told the browser to expect a image of type jpeg with
context.Response.ContentType = "image/jpeg"

so it is not expecting you to also send plain/html text, so it will either ignore it or maybe lump it in with the image data, either way it will not display it.
NMehta83 25-Oct-10 6:41am
If you remove this line 'context.Response.ContentType = "image/jpeg"' then also it will not show you the plain/html text. I also tried it.
Sifar - 0 25-Oct-10 6:44am
Yes, I had also tried this.... removing "image/jpeg". No Use. :(
Rod Kemp 25-Oct-10 7:45am
Removing the ContentType has no effect because browsers can display jpg files internally so the first thing a browser sees is a jpg file header and the assumption is made that all data that follows is image data, if you were trying to push a zip or a pdf file out with BinaryWrite and no ContentType you would normally see something very different.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 25 Oct 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100