Max Zhukov
Max Zhukov

Reputation: 897

Set asp:Image picture from System.Drawing.Image

I have database with Image field, and asp:FileUpload on the page. Method for save image is

protected void btnUploadImage_Click(object sender, EventArgs e)
{
    Stream str = uplReportImage.FileContent;
    //записать в файл   
    ViewHolder.CurrentTemplate.HeaderLogo = System.Drawing.Image.FromStream(str);
}

So, in my ViewHolder I have System.Drawing.Image field. How can I set it to asp:Image control?

Upvotes: 0

Views: 703

Answers (2)

Patrick Hofman
Patrick Hofman

Reputation: 156978

I would write a HttpHandler that fetched the image from a specific url. You can use the url in your pages, and fetch it in the http handler.

This has advantages when browsers cache images, and you can reuse the image easily on different pages.

Upvotes: 1

lavanyadeepak
lavanyadeepak

Reputation: 11

The control has an ImageUrl property which can be set to a unique GUID to a server-side handler, which can parse the GUID and dynamically write the contents of System.Drawing.Image as Response.BinaryWrite by setting an appropriate mime type.

Upvotes: 1

Related Questions