Click here to Skip to main content
15,920,688 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

I am using listview in my webpage, there into i need to bind the images from sqlserver database,for that i used image handler(ashx) but i am unable to get images.

Can any one please help me?
Zafar Sultan 18-Jun-13 6:01am    
Without looking at your code?

1 solution

In your source code you should do something like the next code:

YourDataEntity yourData = _db.YourDataEntities.FirstOrDefault(item => item.ID == ID);
byte[] imageBytes = yourData.Image; //Access the "Image" field from SQL!
MemoryStream stream = new MemoryStream(imageBytes);
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "image/jpeg";
byte[] buffer = new byte[4096];
while (true)
int read = stream.Read(buffer, 0, buffer.Length);
if (read == 0)
response.OutputStream.Write(buffer, 0, read);
Share this answer
Raul Iloc 24-Jun-13 4:00am    
Did you apply my suggested solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900