Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

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

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 I want the image to be shown.

How do I return it exactly?
  • 3
1 Solution
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"

Open in new window

Oops, sorry, there is a typo in the contenttype, it should be "image/jpeg".
NewtonianBAuthor Commented:
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.}"
Oh, the cause of the exception is here:

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.
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.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now