Displaying Images in ASP.NET Using HttpHandlers
page 1 of 8
Published: 18 Jul 2007
This article explains HttpHandlers and how to use them to display images in ASP.NET.
by Electronic Screw
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 114671/ 109


Most of the time when developing web applications/projects we find the need to display images on the ASP.NET pages. This can include customer pictures, avatars, location maps or other binary data. One good way of doing this is to have a dummy page called, which writes out the binary data using the Response.BinaryWrite() as explained in this article. This article explains using an HttpHandler to display the images.

View Entire Article

User Comments

Title: Very Good article   
Name: Jayesh Sorathia
Date: 2013-01-28 2:50:06 AM
You can Get Image from Generic HTTP Handler file by implementing HttpHandler interface.
Here is live downloadable C# Examples and VB.Net Examples.
Title: image display   
Name: S.sreelkshmi
Date: 2012-08-31 3:37:10 AM
How to display an image into the web page in asp.net
Title: image display .   
Name: priya
Date: 2012-02-21 10:40:24 AM
how to add image in asp.net using vb with ms access oledb connectivity.display, save, retrieve and delete the image.
Title: Prefent lost Image   
Name: Raul
Date: 2011-10-06 3:46:00 PM
How to prevent lost image uploaded with ajax upload file control and showded with image Handler on dropdown postback auto postback??
Title: Thanks   
Name: Burak TARHANLI (from Turkey)
Date: 2011-10-04 10:28:21 AM
This is an excellent article. Thank you so much.
Title: Question...   
Name: Hans Peter, Denmark
Date: 2010-02-11 2:21:40 AM
I have an image saved into a MSSQL Server as varbinary(MAX). How do I get this image and execute it using a handler?

I have found some code here:
Public Sub getImage()
Dim connectionString As String
Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
connectionString = "*******"
Dim UserId As String = System.Web.Security.Membership.GetUser().ProviderUserKey.ToString
connection = New SqlConnection(connectionString)

Dim command As New SqlCommand("SELECT Img1 FROM Nomogram WHERE bID=133", connection)
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
Dim picture As Image = Nothing
'Create a stream in memory containing the bytes that comprise the image.
Using stream As New IO.MemoryStream(pictureData)
'Read the stream and create an Image object from the data.
picture = Image.FromStream(stream)
End Using
End Sub

Any idead on how to display it`?
Kind regards Hans Peter
Title: give the informaion very easy format   
Name: venu
Date: 2008-12-23 9:51:31 AM
u will provide the information very easy
Title: Thanks   
Name: Gabriel
Date: 2008-11-27 3:53:58 AM
Thanks! That was easy and helpful.
Title: please provide the details of storing images in database using asp.net   
Name: danny
Date: 2007-10-12 9:36:01 AM
please provide the same at the earliest
Title: Response to: Missing a Reference for dsImagesTableAdapters?   
Name: Mark
Date: 2007-08-30 9:51:30 AM
My bad: I'd put the xsd and xss files in the app_data folder.

Excellent example!
Title: Missing a Reference for dsImagesTableAdapters?   
Name: Mark
Date: 2007-08-30 9:26:30 AM
Where do we make the reference to the dsImagesTableAdapters?

Title: nice   
Name: abc
Date: 2007-08-24 1:30:55 AM
nice concept
Title: ASP.NET   
Name: sadat arsalan
Date: 2007-07-21 1:17:42 PM
tell me about buttons coding in ASP.NET using HTML codes
Title: Displaying Images in ASP.NET Using HttpHandlers   
Name: Electronic Screw
Date: 2007-07-19 5:34:45 AM
Yes, you could do that and the content-type was the "key" to that. I'm writing on that and will be available in a couple of days.

Title: Displaying Images in ASP.NET Using HttpHandlers   
Name: Jeff
Date: 2007-07-18 10:50:17 AM
Could you use this same sort of set up to pull things like .doc or .pdf files that might be stored in a database?

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-01 3:54:29 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search