Solved

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

Posted on 2010-11-15
4
845 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

689 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