ASP.NET Website Development - Displaying Images From SQL Server Database

Awhile back I mentioned this cool project on CodePlex entitled Image Generation:

Fast forward to this past week when I needed to display images in a SQL Server Database on a client's website. This is a pretty simple task - one I have done dozens and dozens of times. However, in this case, I remembered this Image Generation Project on CodePlex and decided to try it out.

Although it is not much different than how I normally do it, using a custom HTTP Handler to serve up the images asynchronously from the database, I really like the combination of using a Dynamic Image Like ASP.NET Server Control, called GeneratedImage, with a custom HTTP Handler.

What is really interesting is that the steps and code is really as simple as shown on the project's main page. If you are interested in displaying images from a SQL Server Database, there is an example of doing it with LINQ To SQL in the QuickStarts.

  1. Download the Microsoft.Web.GeneratedImage.dll assembly from the project and reference it in your ASP.NET Website or ASP.NET Web Application Project.
  2. Create a custom HTTP Handler that derives from a base class they provide - ImageHandler.
  3. Register the Microsoft.Web.GeneratedImage Assembly with the page and add the custom GeneratedImage ASP.NET Server Control to your page.

Honestly it really is that simple.

In my case I was using ADO.NET instead of LINQ To SQL. If you are using ADO.NET or the Data Access Application Block, you can use one of these tutorials for some sample ADO.NET Code:

 

I realize I haven't provided much more information than I did in the original post above, but the ASP.NET server control and custom HTTP handler are very, very trivial to create and use. I just wanted to mention this project again in case others were not aware of it. It is very cool and easy to use for displaying images in a SQL Server Database on your ASP.NET Website. Note you can use it for displaying dynamic images as well.

Click here to go directly to the ASP.NET Image Generation Project on CodePlex.

 

posted on Wednesday, October 22, 2008 12:13 AM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices