0

Here is how my code is:

page.aspx:

<asp:Image ID="Image1" runat="server" />

Code behind:

byte[] IMG = class.readImg(id);
Image1.ImageUrl = "~/page.aspx?ID=" + id.ToString();
Context.Response.ContentType = "image/jpg";
Context.Response.BinaryWrite(IMG);

Whith this code, the only thing that shows in page.aspx is the image read.

João Paulo
  • 6,300
  • 4
  • 51
  • 80

2 Answers2

2

NO need to use a HttpHandler

just use the following code retrieve data from SQL Server into DataTable.

Into .ASPX page

<img runat=server id="logoImg" alt="" src="" />

Into C# Code

byte[] imgArray =  (byte[])dTable.Rows[0][8];
logoImg.Src = "data:image/png;base64," + Convert.ToBase64String(imgArray);
andrewsi
  • 10,807
  • 132
  • 35
  • 51
Khaled
  • 21
  • 2
0

Here's a solution from a similar, recent question:

Display image from database in ASP.net with C#

You need to use a HttpHandler class to retrieve and write the stream.

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91