Adding Bar Codes to Receipts in AspDotNetStorefront

Adding Bar Codes to Receipts in AspDotNetStorefront

Sample Administrative Notification ReceiptA recent posting in the AspDotNetStorefront forums got my brain spinning on how best to accomplish this. The technology to do this, once written, should be able to be leveraged in other areas that clients of mine have been looking to do. So, out comes Visual Studio and Google to come up for some starting points on how to accomplish this.

Research pointed me at an article by Zach Smith on TechRepublic that provided the basis for this project.  With this, I created a class file to place in the site’s /App_Code directory containing the following code:

One of the key features of this code is the font that is used to create the barcode. Matthew Welch has released a number of freely available TrueType fonts at his site I Shot the Serif. The font in question is his “Free 3 of 9” which will produce a 3 of 9, or Code 39, barcode that is scannable by my hand-held scanners. You will need to download the fonts and install them into the %windir%\font directory on the server running the storefront. One thing that is very important is that the font won’t be available until either the server is rebooted or you’ve run IISRESET on the server. Normally the font is available immediately as soon as it is added to the server’s font directory to most applications but working with IIS6 on a Win2k3 server and IIS7 on a Vista box required an IISRESET to enable the font.

Next, we need to create a file in the website that will will actually generate the barcode image on the fly. This is done in the code-behind of the CreateBarCode.aspx file:

You’ll notice that in the call to BarCode.BarCode.CreateBarcode() includes an asterisk before and after the actual code to be encoded into the barcode. This is because Code39 barcodes are supposed to be enclosed in asterisks in order for scanners to identify the barcode type. This simple file just takes the querystring value named “data” and passes it (after enclosing it in *) to the CreateBarcode() function in the BarCode class in the BarCode namespace.

Lastly we will need modify the XMLPackage to generate the call to this image. In my client’s case, they want this to show up in the administrative notification email which is printed for the order pickers. As such, I added the following code to the appropriate location in the notification.adminneworder.xml.config file that generates this email.

In this case, the table row is inserted into the tblOrderHeader table generated by the order ID. Please note that I’ve used two different
methods to pull in the order number into the <img> tag for illustrative purposes; either one will work

Hopefully someone else will find this handy. If so, please leave a note in the comments field below. Of course, if the work to implement this is beyond your abilities or the time available to you, please feel free to contact us and we’ll contract to do the work for you.

Stalk Me...

Michael Gibbs

I'm a technologist at heart, assisting companies best utilize the Internet to market themselves and sell their products and services online. This includes organizations as large as Google and as small as one or two individuals.
At Over The Top and Exhibit A Communications, I've programmed solutions for Google as well as at least one other company that was later acquired by Google.

I've been CTO of an Internet SaaS company and spent my time pretty evenly between guiding the future technical strategy of the company, architecting software solutions for my dev teams, designing and running a data center to service our clients world-wide as well as being a technical evangalist/sales engineer to our media clients large and small.

I've also been Chief Photographer of the Daily Sun/Post newspaper back when it was a 5-day a week daily newspaper.

I also spent a great many years as a beach lifeguardfor the City of San Clemente as well as Jr. Lifeguard instructor and then as it's program coordinator.
Bragging rights
Private Pilot with Instrument rating and proud husband of soon to be 25 years (and counting).
Stalk Me...

Latest posts by Michael Gibbs (see all)

Leave a Reply