Solved

c# .net, memorystream in code to image with request

Posted on 2010-11-15
4
829 Views
Last Modified: 2012-05-10
I have an HTTP request to my c# application that generates a memorystream, I want this request to return that memorystream as an image just as if I were to go on lets say google.com/myimage.jpeg I want the image to be shown.

How do I return it exactly?
0
Comment
Question by:NewtonianB
  • 3
4 Comments
 
LVL 3

Expert Comment

by:xeonol
ID: 34142582
I assume that the MemoryStream is named ms and the image type is JPEG, then you can return it simply with
 
Response.ContentType = "image/png"

Response.BinaryWrite(ms.ToArray)

Response.End()

Open in new window

0
 
LVL 3

Expert Comment

by:xeonol
ID: 34142585
Oops, sorry, there is a typo in the contenttype, it should be "image/jpeg".
0
 

Author Comment

by:NewtonianB
ID: 34148593
On response.end I get
"[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}"
0
 
LVL 3

Accepted Solution

by:
xeonol earned 500 total points
ID: 34152976
Oh, the cause of the exception is here: http://support.microsoft.com/kb/312629/EN-US/

As it suggests, we should call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution.

Sorry for the mistake.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now