Click here to Skip to main content
Email Password   helpLost your password?

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:

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.

<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.

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

Finally

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Question[My vote of 2] Article Intro Purpose
stixoffire
3:30 15 Dec '09  
I am not really understanding the purpose of this control.
I understand displaying the Barcode ..OK ..
What is the purpose of displaying some other image or as in the example of images given - please describe this so I can understand perhaps the need for such a control or the point of this control and therefore the article.

Thank you..
AnswerRe: [My vote of 2] Article Intro Purpose
RMostafa
3:34 15 Dec '09  
You need to read the referenced article Control to Display Binary Images in ASP.NET[^] in order to understand basically the control does display binary images by direct binding from the database without the need to make any extra effort. also it allows you to generate thumbnail from this image or the bar code image on the fly by just specifying DisplayThumbnail and the ThumbnailSize properties it also allows to take an empty image so that if the image isn't there or the bytes passed is null it displays the given empty image.

Regards
Ramy
GeneralRe: [My vote of 2] Article Intro Purpose
stixoffire
3:52 15 Dec '09  
So you are saying this is simply an image handler that also allows you to display the barcode of a represented image ?

I understand about getting an image from SQL database in Binary and translating that into Image - only a few lines of code there. If Null display other not too difficult there either.. I do not need a separate handler for this - as I can D/L from DB and resize on the fly. If I can remember my code correctly I do this in the Eval statement on codebehind as I grab each image.. I use a reference to a DLL in my code to do this.

But where does the Barcode come in ?
And why do I need to add that - is this just combining functionality into one DLL ?

I do have a pretty complete Barcode DLL library - that I found on codeproject - that renders several different barcode formats as an image of the Barcode ..

Again this still leaves me of a question for your article..
GeneralRe: [My vote of 2] Article Intro Purpose
RMostafa
4:50 15 Dec '09  
Well basically lets think of the first version that, a normal Image control isn't able to directly display Binary Image from the database so you tend to make a handler and pass for the image the URL of the handler and the id of the image you want to display. so the first version was an enhanced image control that would let you display by direct binding a database image you could write in C# code for ex. RbmBinaryImage1.ImageContent = FileUpload1.FileBytes; and the image will be displayed also you could bind the image field from the database directly to the ImageContent Property. This was the main functionality so there was some other added functionality like getting a thumbnail from this image, displaying a specified empty image if there is no content.

Then in this version, I've added that the control could display directly BarCode since normally for displaying the bar code image from most of the libraries they return an Image which still would need a specified handler for it. so instead of using two things you could now use this image control to directly display bar code by binding to it the code you want to generate the bar code for it. and yet you could use the other functionality like getting a thumbnail from this bar code etc.

Regards
[Ramy Mostafa]
GeneralArtice needs emprovment
emilio_grv
6:18 11 Dec '09  
Although the idea can be useful, the article should be better improved, explaining not only your motivations and how to use the code but also "why" you did the code as you did: which choices did you made, which alternatives you evaluated (and why didn't you apply) the problem you encounter and which things can be "tricky" to someone who will not just use your code but also improve it adding more functionality and so on.

2 bugs found.
> recompile ...
65534 bugs found.
D'Oh!


Last Updated 11 Dec 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010