Click here to Skip to main content
6,629,377 members and growing! (22,890 online)
Email Password   helpLost your password?
Web Development » ASP.NET » Howto     Advanced License: The Microsoft Public License (Ms-PL)

Display images from SQL Database - the easy way

By FF77

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 an usual image control).
VB (VB 7.x, VB 8.0, VB 9.0), .NET (.NET 2.0, .NET 3.0, .NET 3.5), ASP.NET, Dev
Posted:5 Jul 2008
Views:9,845
Bookmarked:16 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
2 votes for this article.
Popularity: 0.75 Rating: 2.50 out of 5

1
1 vote, 50.0%
2
1 vote, 50.0%
3

4

5

Introduction

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

Background

This project was inspired by an article on code-project written by dev2dev: Article
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 <httpHandlers> section in webconfig:
<add verb="*" path="*.jpg" type="VSCustomRendererLibrary.VsImageHandler, 
VSCustomRendererLibrary"/>

If you cannot find this section in your webconfig 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 an sql table or view (this project was tested with the 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 webcontrol now works with Ajax.
This controls no longer saves images to disk in order to display them. The pictures are displayed directly from memory through a 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


Member

Occupation: Software Developer (Senior)
Location: Romania Romania

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
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  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Jul 2008
Editor:
Copyright 2008 by FF77
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project