Solved

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

Posted on 2010-11-15
4
836 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

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

Suggested Solutions

Title # Comments Views Activity
How to create an MVC5, Razor Widget 2 38
C# XML Get Values 4 35
asp.net web app 3 22
Return array 3 20
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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