How to Generate Barcode in ASP.NET Using C#

Create, encode, insert and print barcode images dynamically in ASP.NET web using C# with examples
Products
Barcode in ASP.NET
Tutorial
Demo now
License & Price
2D Barcode for ASP.NET
1D Barcode for ASP.NET
Barcode in ASP.NET
Barcode Generator/Library DLL/SDK to Create Barcode Image in C# ASP.NET Website - Overview
ASP.NET Server Barcode Control & Generator DLL is the specific barcode solution tool to generate and create barcode as images in ASP.NET applications, the generated linear & 2D barcodes may be displayed in web browser as Gif, Tiff, Bmp, Png or Jpeg formats. Developers may use image tag to embed barcode images in html pages or aspx pages. Free barcode generator DLL for ASP.NET with trial package is provided with barcode generation examples in C#, VB.NET, IIS and ASP.NET class.
This page gives a detail view to create barcode images in ASP.NET using C#; free sample C# code is provided with detail users’ guide. For VB.NET developers, please refer to guide to create barcode images in ASP.NET using VB.NET. Common users may navigate to four methods to create barcode images in ASP.NET, such as IIS, ASP.NET class.
Free Trial Barcode Generator DLL in ASP.NET Using C# - Prerequisites and Development
Requirement
  • Terrek Barcode Generator DLL for Windows Applications
  • Microsoft .NET Framework 2.0, 3.0, 4.0 or above
  • Microsoft Visual Studio 2005 / 2008 / 2010 (any version)
  • Visual C#.NET (any version)
  • OS system above Windows 2000, such as Windows XP, Windows Vista, Windows 7, etc
Solution Project Development
  • ASP.NET Web Site (design-time and runtime support)
  • Console Application (runtime support)
  • Class Library (runtime support)
  • ASP.NET Web Services (runtime support)
Create Barcode Images in ASP.NET Applications Using C# with Barcode DLL - Installation
Using C#.NET programming is easy and simple to create barcode images in ASP.NET, including 40+ linear and 2D barcodes. The class encodes data into the appropriate symbology format and sends the barcode string to the default printer. It is important that the appropriate ASP.NET barcode DLL is installed.
Install Barcode Generator & Library DLL in C# ASP.NET
  • Download barcode generator control SDK for ASP.NET and unzip
  • Copy barcode DLL in the C#.NET project directory in hard drive where the project created
  • Copy documents barcode.aspx and barcode.aspx.cs to the folder where you generate barcode
  • Add the ASP.NET barcode dll file to the project reference in Visual Studio 2005, 2008 or 2010
Barcode Generator/Control to Create Barcode in ASP.NET Using C# - Barcode Generation
  • Start your Visual Studio 2005, 2008 and 2010
  • Create a web application using the installed project templates in C# projects;
  • Right-click the project in the solution explorer, and add a reference
  • Right click on the Default.aspx and select View Code
  • Include the Terrek.barcode namespace to the solution. That is using Terrek.barcode;
  • Once the reference to the using Terrek.barcode namespace is added to the C# solution, the bar code object may be instantiated, that is BarCode barcode = new BarCode();
  • Use the C# methods associcated with the barcode system, method in the C# class take a string as an input value and encode the data to the format of the symbology. 40+ linear and 2D barcode types, functions and features are built into the ASP.NET applications with default value
  • Debug the ASP.NET project after barcode coding in C#
Sample C# Coding to Generate Barcode Images in ASP.NET Project
We provide the detail example of generating Code 128 in ASP.NET using C#. To create other barcode symbols, please change the C# code accordingly.
using Terrek.Barcode;
BarcodeControl code128 = new BarcodeControl();
//auto code set (Code128), A(Code128_A),B(Code128_B), C(Code128_C)
code128. Symbol = BarcodeSymbol.Code128;
code128.BarcodeData = "Code128";
//Code128 image setting
code128.DotsPerInch = 96;
code128.BarcodeFormat = System.Drawing.Imaging.ImageFormat.Png;
code128.drawBarcode("C:\\code128.png");
//Code 128 size setting
code128.ImageResize = true;
code128.MeasuringUnit = MeasuringUnit.PIXEL;
code128.BarWidth = 2;
code128.BarHeight =50;
code128.ImageWidth = 0;
code128.ImageHeight = 0;
code128. MarginL = 10;
code128. MarginR = 10;
code128. MarginT = 10;
code128. MarginB = 10;
//Code 128 human-readable text customization
code128.TextStyle = new Font("Arial", 9f, FontStyle.Regular);
code128.TextColor = Color.Black;
code128.TextSpace = 6;
code128.DisplayData = true;
//Code 128 barcode placement setting
code128.Rotation = Rotation.Degree0;
code128.BarAlign = BarAlign.Center;
//Code 128 color setting
code128. ImageColor = Color.White;
code128. BarColor = Color.Black;