|
Home > .NET Barcode
> Barcode Generation Guide
> C# Barcode Generation Guide
C# Barcode Generation Guide
Generating Linear & 2D Barcodes in C# Windows, C# ASP.NET Projects
- Easy & Simple to generate barcodes in C#.net
- Generate high quality JPEG, GIF & PNG barcode images
- 100% build in managed C#
- Mature C#.net barcode component since 2003
- Compatible with latest barcode symbology standards
- Create linear barcodes, including Code39, Code128, GS1-128, Interleaved 2 of 5, EAN / UPC
- Create 2d barcodes, including Data Matrix, PDF-417, & QR-Code
- Royalty-free and perpetual developer license
This article introduces how to use Barcode for .NET component to generate barcodes in your Visual C# ASP.NET website, C# classes, and C# Windows applications.
C# Barcode Generator Supporting Symbologies
- C# Barcode Generates 1D (Linear) Barcode Symbologies
- C# Barcode Generates 2D (Matrix) Barcode Symbologies.
C# Barcode Generator - Generating Barcodes in C#.NET Class
Install:
Add BarcodeLib.Barcode.dll to your C# project reference.
Implement:
1: BarcodeLib.Barcode.Linear.Linear barcode = new BarcodeLib.Barcode.Linear.Linear();
2: barcode.Type = BarcodeLib.Barcode.Linear.BarcodeType.CODE39;
3: barcode.Data = "123456789";
4: // other barcode settings.
5:
6: // save barcode image into your system
7: barcode.drawBarcode("c:/barcode.png");
The above code is written in Visual C# 2005
- Create an linear barcode object (BarcodeLib.Barcode.Linear.Linear).
- Set barcode type to Code 39
- Set your encoded barcode value
- Draw barcode image into a PNG file
C# Barcode Generation - Generating Barcode in ASP.NET Web Applications
There are two methods to create barcode images in your ASP.NET web applications using C#.net.
-
The Simplest way is to stream barcode image using our Buildin ASP.NET Barcode Application.
- 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=CODE39&Data=12345678
- To create barcode image in your aspx or html page, you need pass the url to IMG tag src value.
For linear barcode
<img src="http://YourDomain:port/barcode/linear.aspx?Type=CODE39&Data=12345678" />
or for Data Matrix
<img src="http://YourDomain:port/barcode/datamatrix.aspx?Data=12345678" />
or for PDF417
<img src="http://YourDomain:port/barcode/pdf417.aspx?Data=12345678" />
or for QRCode
<img src="http://YourDomain:port/barcode/qrcode.aspx?Data=12345678" />
Using this method, it will not generate any barcode images in your IIS server side.
-
The second method is to generate barcode images through ASP.NET Web Form controller
- Install .NET Barcode Controller to your ASP.NET project.
- Add Reference BarcodeLib.Barcode.dll to your project. Do not copy the dll to the bin directory, Visual Studio will do so, during project compilation time.
- Copy linear.aspx file to your web application.
- 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.dll file.
- Then sort "Namespace" column, you will find 8 components from BarcodeLib.Barcode.
- Check component DataMatrixWebForm, and its namespace is BarcodeLib.Barcode.DataMatrix
- Check component LinearWebForm, and its namespace is BarcodeLib.Barcode.Linear
- Check component PDF417WebForm, and its namespace is BarcodeLib.Barcode.PDF417
- Check component QRCodeWebForm, and its namespace is BarcodeLib.Barcode.QRCode
do not select WinForm controls, which are for Windows Forms.
- Click "OK" button, you will find four components under "General": LinearWebForm, DataMatrixWebForm, PDF417WebForm, QRCodeWebForm.
- Go to "barcode" folder in the trial package, copy files "linear.aspx", "datamatrix.aspx", "pdf417.aspx", "qrcode.aspx" to the same folder as your aspx page, which will generate barcodes.
- You can drag LinearWebForm on your aspx page, change barcode setting through properties window.
- Run the project, you will find barcode images generated in your aspx pages.
C# Barcode Generation - Generating Barcodes in C# Windows Applications
- Add Reference BarcodeLib.Barcode.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.dll to your project.
- 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.dll file.
- Then sort "Namespace" column, you will find 8 components from BarcodeLib.Barcode.
- Check component DataMatrixWinForm, and its namespace is BarcodeLib.Barcode.DataMatrix
- Check component LinearWinForm, and its namespace is BarcodeLib.Barcode.Linear
- Check component PDF417WinForm, and its namespace is BarcodeLib.Barcode.PDF417
- Check component QRCodeWinForm, and its namespace is BarcodeLib.Barcode.QRCode
do not select WebForm controls, which are for ASP.NET Web Forms.
- Click "OK" button, you will find four components under "Common Controls": LinearWinForm, DataMatrixWinForm, PDF417WinForm, QRCodeWinForm.
- Now you can see the component displayed on Toolbox. You can drag LinearWinForm on your form, change barcode setting through properties widnow.
Other Related Articles
|