Generating Barcodes in ASP.NET Websites
Quick Navigate
1. Run Demo Web 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.
- Open your web browser, and navigate to http://YourDomain:Port/barcode/linear.aspx?Type=CODE39&Data=12345678
- To view demo application source code (in C#), go to folder barcode in the trial package.
2. Install & Integrate Barcode for ASP.NET DLL Component
There are two methods to create barcode images in your ASP.NET web applications.
-
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 QR Code
<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 ASP.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.
- 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 DataMatrixASPNET, and its namespace is BarcodeLib.Barcode.
- Check component LinearASPNET, and its namespace is BarcodeLib.Barcode.
- Check component PDF417ASPNET, and its namespace is BarcodeLib.Barcode.
- Check component QRCodeASPNET, and its namespace is BarcodeLib.Barcode.
- Click "OK" button, you will find four components under "General": LinearASPNET, DataMatrixASPNET, PDF417ASPNET, QRCodeASPNET.
- Go to "barcode" folder in the trial package, copy files "linear.aspx", "linear.aspx.cs", "datamatrix.aspx", "datamatrix.aspx.cs", "pdf417.aspx", "pdf417.aspx.cs", "qrcode.aspx", "qrcode.aspx.cs" to the same folder as your aspx page, which will generate barcodes.
- You can drag LinearASPNET on your aspx page, change barcode setting through properties window.
- Run the project, you will find barcode images generated in your aspx pages.
3. Generate Barcodes in .NET Class
The following C#.net code illustrates how to generate a 1d (linear) barcode in a C# class
BarcodeLib.Barcode.Linear barcode = new BarcodeLib.Barcode.Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.UOM = UnitOfMeasure.PIXEL;
barcode.BarWidth = 1;
barcode.BarHeight = 80;
barcode.LeftMargin = 5;
barcode.RightMargin = 5;
barcode.TopMargin = 5;
barcode.BottomMargin = 5;
barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
// save barcode image into your file 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);
4. Property Settings for Each Barcode Types
Copyright BarcodeLib.com. All rights reserved.
|
|