Click here to Skip to main content
15,881,794 members
Articles / Web Development / ASP.NET

Displaying Binary Images and Barcode

Rate me:
Please Sign up or sign in to vote.
4.16/5 (8 votes)
11 Dec 2009MIT2 min read 41.3K   1.2K   29   6
This is an update to the RbmBinaryImage control - to display barcodes.

Introduction

One of my friends was asking me how to display barcodes in ASP.NET. There is a great Open Source code written by Bart De Smet which can return a bar code image from a bar code string; you could see his article here. I have just added to it a small option of whether or not to display the code under the bar code. The library returns an Image. I thought, adding the display of the bar code from the bar code string value to RBMBinaryImage would be cool.

Background

In the last version of RBMBinaryImage on CodeProject, some people pointed out that the control worked in Visual Studio perfectly but not well on some servers. I place here a solution for this problem posted by Louis, on of the control users on my site for the RBMBinaryImage, for users using the old version.

  1. Open IIS and open the properties for the website you want the handler to work for.
  2. Open Handler mappings and select a file extension which is served by ASP.NET, like .aspx, and click Edit.
  3. Copy the file that's used over there (should be %windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll).
  4. Close the dialog and click Add Script Map... to add a new one. Put the copied value in the right textbox, and fill in .rbm as the extension you want to be handled - uncheck the option "Verify that file exists" when mapping the application extensions.
  5. Next, close all open boxes by clicking OK, and you should be ready to go.

In the new version of the control, we can display a barcode as an image. Shown below is a screenshot:

Image 1

Using the code

The idea was simple since, the Code39 library returns an Image object, so I only got its bytes and passed it to the ImageContent property, which is then rendered in the image. For more information on how the binary image display works in RBMBinaryImage, please see the post here. Again, the usage of the control is very easy. To display the barcode, you only need to set the PrintBarcode property to true, and pass to the BarCodeValue the barcode. As you can see below, the DisplayThumbnail property is still being applied on the bar code.

ASP.NET
<Rbm:RbmBinaryImage ID="RbmBinaryImage2" runat="server" 
    PrintBarcode="true"  BarCodeValue='<%# Eval("BarCode") %>' 
    DisplayThumbnail="true"   ThumbnailSize="160" 
    EmptyImageUrl="images/NoPhoto.JPG" />

I have made a change to the HttpHandler to be with the extension .ashx instead of .rbm, to be standard compliant.

XML
<httpHandlers>
  <add verb="GET" path="__RbmImageHandler.ashx" type="RbmControls.RbmImageHandler"/>
</httpHandlers>

Finally

You can download the latest version of the project from here.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
Egypt Egypt
Fun Coder Smile | :) My Job is my Hobby Smile | :)

Comments and Discussions

 
GeneralBarCode Image Format Pin
Z@clarco22-Nov-10 23:13
Z@clarco22-Nov-10 23:13 
Question[My vote of 2] Article Intro Purpose Pin
stixoffire15-Dec-09 2:30
stixoffire15-Dec-09 2:30 
AnswerRe: [My vote of 2] Article Intro Purpose Pin
rmostafa15-Dec-09 2:34
rmostafa15-Dec-09 2:34 
GeneralRe: [My vote of 2] Article Intro Purpose Pin
stixoffire15-Dec-09 2:52
stixoffire15-Dec-09 2:52 
GeneralRe: [My vote of 2] Article Intro Purpose Pin
rmostafa15-Dec-09 3:50
rmostafa15-Dec-09 3:50 
GeneralArtice needs emprovment Pin
Emilio Garavaglia11-Dec-09 5:18
Emilio Garavaglia11-Dec-09 5:18 

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

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