Barcodes are defined as “…an optical machine-readable representation of data relating to the object to which it is attached.” (per Wikipedia). If you want to know which industry used “barcodes” first than scan the barcode at the bottom of this article, you could also read it in my code section (not as much fun). It began around the 1960 and has ballooned to now include barcodes on everything from apples to zebras (not really) but zebras do have stripes.
Anyway barcodes are great to use for just about anything. I mostly use them on documents when they are printed but can contain just about anything. There is a great .dll library for .net that helps in adding barcodes to your page at runtime. It is called ZXing.Net and will handle QR Code, PDF 417, EAN, UPC, Aztec, Data Matrix, Codabar and a few others.
Scott Hanselman has a great article on using this barcode in a WPF application but I am going to use a simple web form example. Once you understand how to implement this you can use it for anything.
I will also give you a few thoughts on barcoding at the end….Let’s get started.
1. Launch VS 2012 and create a new web blank project.
2. Add a reference to the zxing.dll (get it here)
3. Create a blank web form and add this to the page.
4. In the code behind on the blank web form add this.
Imports System.IO Imports ZXing Imports ZXing.QrCode Imports System.Drawing.Imaging Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'http://zxingnet.codeplex.com/discussions/470355 'http://www.hanselman.com/blog/HowToDisplayAQRCodeInASPNETAndWPF.aspx Dim qrCode As New QRCodeWriter() Dim qrValue As String = "Railroads" Dim BarcodeWriter As New ZXing.BarcodeWriter BarcodeWriter.Format = ZXing.BarcodeFormat.QR_CODE 'BarcodeWriter.Format = ZXing.BarcodeFormat.CODE_39 BarcodeWriter.Options.Height = 200 BarcodeWriter.Options.Width = 400 BarcodeWriter.Options.Margin = 1 Using bitmap = BarcodeWriter.Write(qrValue) Using stream = New MemoryStream() bitmap.Save(stream, ImageFormat.Gif) Dim img = New StringBuilder() img.Append("<img alt="" src=" + [String].Format(" />") Response.Write(img) End Using End Using End Sub End Class
Some points to remember when using barcodes.
- 1. In closing keep in mind that each type of barcode does have some limitations
- 2. If you are using QR code (designed for smart devices) then make sure where you are sending them have a mobile-UI otherwise their experience will be less than pleasant.
- 3. I use a QR on business cards and such which directs them to a page like. (http://www.mysitename.com/businesscard) Then I use google analytics to track that they came from my business card and then do an automatic redirect to http://www.mysitename.com. I realize this method is not perfect but it does help understanding where your customers are coming from. You could set up one for each of your marketing methods.
- 4. Realize that barcodes are to be read by computer and not humans.
- 5. If you don’t want to build yours “on-the-fly” then you can build it online here
Link to VS2012 Project:Barcoding
Looking for quality web hosting? Look no further than Arvixe Web Hosting!