Click here to Skip to main content
Licence Ms-PL
First Posted 5 Jul 2008
Views 18,132
Downloads 263
Bookmarked 19 times

Display images from a SQL database - the easy way

By FF77 | 5 Jul 2008
This project contains a Web Custom Control for rendering images directly from the database. Can be used with image fields, text, date, or numerical fields (it generates an image containing the text), and with URL fields (like in a regular image control).
1 vote, 33.3%
1
1 vote, 33.3%
2
1 vote, 33.3%
3

4

5
2.20/5 - 3 votes
μ 2.20, σa 1.75 [?]

Introduction

This is version 3.0 of the VsCustomRenderer control. You can find the previous versions here: 2.0 and 1.0.

Background

This project was inspired by an article on CodeProject written by dev2dev: Create Dynamic Images in ASP.NET. Parts of the code were taken from that project.

Using the Code

To test this control:

  • Open or create a website.
  • Add the VSCustomRendererLibrary reference to the website.
  • Add the following line in the <httpHandlers> section in the web.config:
<add verb="*" path="*.jpg" 
  type="VSCustomRendererLibrary.VsImageHandler, VSCustomRendererLibrary"/>

If you cannot find this section in your web.config file, just create it under <system.web>:

<system.web>
    ......
     <httpHandlers>
          <add verb="*" path="*.jpg" 
            type="VSCustomRendererLibrary.VsImageHandler, VSCustomRendererLibrary"/>
     </httpHandlers>
</system.web>
  • Open/create a new ASPX page.
  • Add a SqlDataSource connected to a SQL table or view (this project was tested with SQL Server 2005 EE).
  • Add a GridView and connect it to the SqlDataSource.
  • In the GridView, add the image column and transform it into a template field.
  • Select Edit Template from the GridView toolbar menu.
  • Add a VSCustomRenderer into the ItemTemplate. Bind the control to the DataSource field.

Points of Interest

This Web Control now works with AJAX. This control no longer saves images to disk in order to display them. The pictures are displayed directly from memory through an IHttpHandler. This HTTP handler does not open a new database connection, it just displays the images from memory, so there are no delays in page rendering and no extra parameters to set.

History

All the versions of this control are also posted on CodePlex.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

FF77

Software Developer (Senior)

Romania Romania

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberDeian1:04 18 Mar '10  
QuestionFailure Pinmembervferrava12:09 29 Jul '08  
AnswerRe: Failure Pinmembereduguesser10:44 31 Jul '08  
GeneralRe: Failure PinmemberFF772:53 9 Nov '08  
GeneralAlternative PinmemberVitalyTomilov11:51 5 Jul '08  
GeneralRe: Alternative PinmemberFF7711:58 5 Jul '08  
GeneralRe: Alternative PinmemberHoyaSaxa9314:13 5 Jul '08  
GeneralRe: Alternative [modified] PinmemberVitalyTomilov2:46 6 Jul '08  
GeneralRe: Alternative PinmemberFF773:12 6 Jul '08  
GeneralRe: Alternative PinmemberVitalyTomilov12:01 6 Jul '08  
Note, i did not call it a better alternative Wink | ;)
 
And besides, i did it 3 years ago. Things change..

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 5 Jul 2008
Article Copyright 2008 by FF77
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid