Our Customers
Contact Us Email: support@barcodelib.com
Home > .NET Barcode > Barcode Generation Guide > .NET Code-128 Barcodes Generator for .NET, ASP.NET, C#, VB.NET
Download Barcode for .NET Suite Trial

.NET Code-128 Barcodes Generator Guide

Code-128 Bar Code Generation Guide in .NET, C#, ASP.NET, VB.NET
  • Simple to draw Code-128 barcodes in .NET applications
  • Compatible with the latest Code-128 ISO specification [ISO/IEC 15417 (Second edition 2007-06-01)]
  • Generate high quality Code-128 images in JPEG, GIF & PNG formats
  • Completely built in C# codes, compatible with .net 2.0 and later versions
  • Generate Code-128 barcodes using C#, VB.NET on ASP.NET or Windows Forms
  • Generate Code-128 in Crystal Reports using C#, VB.NET
  • Generate Code-128 in Reporting Services using C#, VB.NET
  • Professional .NET Barcode Generator component supporting all kinds of barcode settings
  • One time payment for royalty-free developer license and use it for lifetime
.NET Code-128 Introduction
Code-128 is also known as ANSI/AIM 128, ANSI/AIM Code 128, USS Code 128, Uniform Symbology Specification Code 128, Code 128 Code Set A, Code 128 Code Set B, Code 128 Code Set C, Code 128A, Code 128B, Code 128C.
Compatibility: Barcode for .NET component is compatible with ISO/IEC 15417 (Second edition 2007-06-01).
Code 128 is a very effective, high-density symbology which permits the encoding of alphanumeric data. The symbology includes a checksum digit for verification, and the bar code may also be verified character-by-character verifying the parity of each data byte. This symbology has been widely implemented in many applications where a relatively large amount of data must be encoded in a relatively small amount of space. It's specific structure also allows numeric data to be encoded at, effectively, double-density.
Code 128 Code Sets
  • Code Set A (or Chars Set A) includes all of the standard upper case U.S. alphanumeric keyboard characters and punctuation characters together with the control characters, (i.e. characters with ASCII values from 0 to 95 inclusive), and seven special characters.
  • Code Set B (or Chars Set B) includes all of the standard upper case alphanumeric keyboard characters and punctuation characters together with the lower case alphabetic characters (i.e. characters with ASCII values from 32 to 127 inclusive), and seven special characters.
  • Code Set C (or Chars Set C) includes the set of 100 digit pairs from 00 to 99 inclusive, as well as three special characters. This allows numeric data to be encoded as two data digits per symbol character, at effectively twice the density of standard data.
Code 128 Special characters
The last seven characters of Code Sets A and B (character values 96 - 102) and the last three characters of Code Set C (character values 100 - 102) are special non-data characters with no ASCII character equivalents, which have particular significance to the bar code reading device.

Sample of a Code 128 Barcode
.NET Code-128 Encoding Data Scope
Code 128 Barcode for .NET, ASP.NET supports:
  • All 128 characters of ASCII
How to Generate Code 128 Barcode Image in IIS without Visual Studio .NET?
  • Under downloaded trial package, copy barcode folder to your IIS folder, e.g. C:\Inetpub.
  • Create a new virtual directory in IIS, named barcode, and link to the above "barcode" folder.
  • Restart IIS.
  • To test your installation, open your web browser and navigate to:
    http://YourDomain:port/barcode/linear.aspx?Type=2&Data=123456789012
  • To create barcode image in your aspx or html page, you need pass the url to IMG tag src value.
    For example:
    <img src="http://YourDomain:port/barcode/linear.aspx?Type=2&Data=123456789012" />
    Using this method, it will not generate any barcode images in your IIS server side.
How to Generate Code 128 Barcode Image through ASP.NET Web Form Control?
  1. Install .NET Barcode Controller to your ASP.NET project.
    • Add Reference BarcodeLib.Barcode.ASP.NET.dll to your project.
      Do not copy the dll to the bin directory, Visual Studio will do so, during project compilation time.
  2. Add barcode library to your Visual Studio Toolbox.
    • Open Toolbox in Visual Studio. Click menu View, and check submenu Toolbox.
    • Right click Toolbox, click menu Choose Items...
    • Goto .NET Framework Components tab.
    • If no BarcodeLib component found, click Browse... button and select BarcodeLib.Barcode.ASP.NET.dll file.
    • Then sort "Namespace" column, you will find 4 components from BarcodeLib.Barcode.
    • Check component LinearASPNET, and its namespace is BarcodeLib.Barcode.
    • Click "OK" button, you will find four components under "General": LinearASPNET.
  3. Go to "barcode" folder in the trial package, copy file "linear.aspx" to the same folder as your aspx page, which will generate barcodes.
  4. You can drag LinearASPNET on your aspx page in design view, change barcode setting through properties window.
  5. Run the project, you will find barcode images generated in your aspx pages.
How to Generate Code 128 Barcode Image through .NET Windows Form Control in C# or VB.NET?
  1. Add Reference BarcodeLib.Barcode.WinFroms.dll to your project. Do not copy the dll to the bin directory, Visual Studio will do so, during project compilation time.
    • In your .NET windows project, right click mouse over Refereces in your Solution Explorer window. Then click menu "Add Reference ...".
    • Add BarcodeLib.Barcode.WinFroms.dll to your project.
  2. Add barcode library to your Visual Studio Toolbox.
    • Open Toolbox in Visual Studio. Click menu View, and check submenu Toolbox.
    • Right click Toolbox, click menu Choose Items...
    • Goto .NET Framework Components tab.
    • If no BarcodeLib component found, click Browse... button and select BarcodeLib.Barcode.WinFroms.dll file.
    • Then sort "Namespace" column, you will find 4 components from BarcodeLib.Barcode.
    • Check component LinearWinForm, and its namespace is BarcodeLib.Barcode.
    • Click "OK" button, you will find the control under "Common Controls": LinearWinForm.
  3. Now you can see the component displayed on Toolbox. You can drag LinearWinForm on your form, change barcode setting through properties widnow.
How to Generate Code 128 Barcode Image in .NET class?
  1. Add Reference BarcodeLib.Barcode.ASP.NET.dll or BarcodeLib.Barcode.WinFroms.dll to your .NET project (ASP.NET website, Forms, any .NET project).
    In your .NET class:
     BarcodeLib.Barcode.Linear barcode = new BarcodeLib.Barcode.Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = "123456789012";

barcode.UOM = UnitOfMeasure.PIXEL;
barcode.BarWidth = 1;
barcode.BarHeight = 80;
barcode.LeftMargin = 10;
barcode.RightMargin = 10;
barcode.TopMargin = 10;
barcode.BottomMargin = 10;

barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
// more barcode settings here

// save barcode image into your system
barcode.drawBarcode("c://barcode.png");

// generate barcode & output to byte array
byte[] barcodeInBytes = barcode.drawBarcodeAsBytes();

// generate barcode to Graphics object
Graphics graphics = ...
barcode.drawBarcode(graphics);

// generate barcode and output to Bitmap object
Bitmap barcodeInBitmap = barcode.drawBarcode();

// generate barcode and output to HttpResponse object
HttpResponse response = ...;
barcode.drawBarcode(response);

// generate barcode and output to Stream object
Stream stream = ...;
barcode.drawBarcode(stream);
Above code written in C# 2005
How to Save Code 128 Barcode Image using .NET Barcode Generator Windows Control?
In Windows Controller, just call method SaveAsImage(string filename). e.g. SaveAsImage("C:\barcode.gif");
.NET Code-128 Property Settings
  1. Set the Type property to BarcodeType.CODE128, BarcodeType.CODE128A, or BarcodeType.CODE128B, or BarcodeType.CODE128C.
    Web Stream URL Parameter: Type. Value: 2 (Auto), 3 (Set A), 4 (Set B), 5 (Set C). Sample: &Type=2
    • BarcodeType.CODE128 - default (auto):Barcode Library will automatically switch between code sets to encode the ASCII values.
    • BarcodeType.CODE128A - A: Barcode Library will encode the Char Set A which only supports ASCII values from 0 to 95.
    • BarcodeType.CODE128B - B: Barcode Library will encode the Char Set B which only supports ASCII values from 32 to 127.
    • BarcodeType.CODE128C - C: Barcode Library will encode the Char Set C which only supports pairs of digits.
  2. Set the Data property with the value to encode.
    Type is string.
    Web Stream URL Parameter: Data.
    1. Valid Data Scope for Code 128 Auto (BarcodeType.CODE128):
      • All 128 characters of ASCII (ASCII values from 0 to 127)
    2. Valid Data Scope for Code 128 Set A (BarcodeType.CODE128A):
      • Supports ASCII values from 0 to 95
    3. Valid Data Scope for Code 128 Set B (BarcodeType.CODE128B):
      • Supports ASCII values from 32 to 127
    4. Valid Data Scope for Code 128 Set C (BarcodeType.CODE128C):
      • Supports pairs of digits
    5. Sample: "BLSample"
  3. Set the ProcessTilde to true, if you want use the tilde character "~" to specify special characters in Code 128 input data. Default is false.
    • ~1: is used to represent the FNC1 code.
    • ~NNN: is used to represent the ASCII character with the value of NNN.
    • Web Stream URL Parameter: ProcessTilde. Valid values are: "true", or "false".
  4. AddCheckSum property is not applied here. Barcode Library will always add a check character between encoded data and stop character (modulo 103).
  5. Barcode Size Settings.
    • Set property UOM (Unit of Measure) for properties BarWidth, BarHeight, LeftMargin and TopMargin.

      Valid values are UnitOfMeasure.Pixel (0), UnitOfMeasure.CM (1), UnitOfMeasure.Inch (2).
      Default is UnitOfMeasure.Pixel (0).
      Web Stream URL Parameter: UOM. Valid values are: 0, 1, 2.
    • Set the ImageWidth and ImageHeight properties.
      Both types are float.
      BarWidth default is 0 pixel.
      BarHeight default is 0 pixel.
      Web Stream URL Parameter: ImageWidth and ImageHeight.
    • Set the BarWidth (for bar cell width) and BarHeight (for bar cell height) properties.
      Both types are float.
      BarWidth default is 1 pixel.
      BarHeight default is 80 pixel.
      Web Stream URL Parameter: BarWidth and BarHeight.
    • Set the LeftMargin, RightMargin, TopMargin and BottomMargin properties.
      Types are all float. Default are 10.
      Web Stream URL Parameter: LeftMargin, RightMargin, TopMargin, BottomMargin.
    • Set the ResizeImage property to "true" and our component will resize the barcode image if manual setting is invalid.
      Type is bool. Default is false.
      Web Stream URL Parameter: ResizeImage.
    • Set the Resolution property (Value is expressed in DPI - Dots per inch).
      Type is int. Default is 96 dpi.
      Web Stream URL Parameter: Resolution.
  6. Setting up text style in barcode image.
    • Set the ShowText properties. If ShowText is True, barcode data will be displayed with the barcode.
      Type is bool. Default is True.
      Web Stream URL Parameter: ShowText. Valid values are: "true", and "false".
    • Set the TextFont property. The font used to display text in barcode image.
      Type is System.Drawing.Font. Default is new Font("Arial", 9f, FontStyle.Regular).
      Web Stream URL Parameter: TextFont. Value format: [font name]|[font size]|[font style]. Sample Values: "Arial|12|Bold,Underline"
  7. Set Color Related properties.
    • Set the BackgroundColor property. Barcode background color can be changed.
      Type is System.Drawing.Color. Default is BackgroundColor = Color.White.
      Web Stream URL Parameter: BackgroundColor.
    • Set the BarColor property. Barcode bars color can be changed.
      Type is System.Drawing.Color. Default is BarColor = Color.Black.
      Web Stream URL Parameter: BarColor.
    • Set the TextFontColor property. Barcode human-readable data text color can be changed.
      Type is System.Drawing.Color. Default is TextFontColor = Color.Black.
      Web Stream URL Parameter: TextFontColor.
  8. Set the ImageFormat property for barcode image type.
    • Type is System.Drawing.Imaging.ImageFormat.
      Default value is ImageFormat.Png.
      Web Stream URL Parameter: ImageFormat. Valid values are: gif, jpeg, png, bmp, tiff.
  9. Set Rotate property, if you want to rotate barcode image.
    Valid values are as below. Default Value is 0 (RotateOrientation.BottomFacingDown).
    Web Stream URL Parameter: Rotate. Valid values are: 0, 1, 2, 3.
    • 0 (RotateOrientation.BottomFacingDown)
    • 1 (RotateOrientation.BottomFacingLeft)
    • 2 (RotateOrientation.BottomFacingUp)
    • 3 (RotateOrientation.BottomFacingRight)
All Supported .NET Barcode Symbologies
Generate Linear Barcodes:
Generate 2D Barcodes: