5,427,303 members and growing! (14,965 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, VB), .NET (.NET, .NET 2.0, .NET 3.0, .NET 3.5), ASP.NET, Dev

Posted: 5 Jul 2008
Updated: 5 Jul 2008
Views: 2,964
Bookmarked: 12 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
2 votes for this Article.
Popularity: 0.75 Rating: 2.50 out of 5
0 votes, 0.0%
1
1 vote, 50.0%
2
1 vote, 50.0%
3
0 votes, 0.0%
4
0 votes, 0.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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



Occupation: Software Developer (Senior)
Location: Romania Romania

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionFailuremembervferrava12:09 29 Jul '08  
AnswerRe: Failuremembereduguesser10:44 31 Jul '08  
GeneralAlternativememberVitalyTomilov11:51 5 Jul '08  
GeneralRe: AlternativememberFF7711:58 5 Jul '08  
GeneralRe: AlternativememberHoyaSaxa9314:13 5 Jul '08  
GeneralRe: Alternative [modified]memberVitalyTomilov2:46 6 Jul '08  
GeneralRe: AlternativememberFF773:12 6 Jul '08  
GeneralRe: AlternativememberVitalyTomilov12: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-2008
Web17 | Advertise on the Code Project