Shyju
Shyju

Reputation: 218722

C# :How can i set Memory stream as the asp.net image control's source property?

I have an asp.net image control in one ASP.NET page and have a Memory Stream which has an image.How can i convert this memory stream to set it as the image source without storing the image in the hard disk ?

Upvotes: 2

Views: 4089

Answers (2)

Oded
Oded

Reputation: 498992

The image control takes an ImageUrl - a path to where the image is located.

There is no property that takes an actual image (or image data).

What you can do is write a HttpHandler that will stream your images from whatever source - set the ImageUrl to use this handler.

Here is an example for a general file handler using a memory stream - it's a good starting point for what I suggest.

Upvotes: 3

Ilia G
Ilia G

Reputation: 10211

you'll have to either write that file onto disk or make another page (action on the same page?) that writes the content of your MemoryStream into the Response, and then point the image control to that source.

Upvotes: 1

Related Questions