Prerequisites
Download and install the following software on your computer
- Visual Studio 2022
- .NET Framework 4
- OnBarcode.Barcode.BarcodeScanner.dll (For .NET Framework 4.0)
Create an ASP.NET web form (Framework) application with barcode reader using C#
1. Create new ASP.NET web form project
Start Visual Studio 2022 and select "Create a new project".
Select "ASP.NET Web Application (.NET Framework)" in the dialog, and then press "Next" button.
Create a new web project with name "OnBarcodeReaderASPNETWebDemo".
Select Empty project template, and then press "Create"
Now, all auto-generated files for ASP.NET framework barcode reader demo web project could be found in the solution explorer.
Select "ASP.NET Web Application (.NET Framework)" in the dialog, and then press "Next" button.
Create a new web project with name "OnBarcodeReaderASPNETWebDemo".
Select Empty project template, and then press "Create"
Now, all auto-generated files for ASP.NET framework barcode reader demo web project could be found in the solution explorer.
2. Install Barcode Reader Library dll
Add OnBarcode Barcode Reader library for .NET Framework 4 reference "OnBarcode.Barcode.BarcodeScanner.dll".
3. Add web page to the project
Open "Add New Item" dialog by press [Ctrl+Shift+A]; and add a new item "Index.aspx" to the project.
Copy ALL following codes to replace the content of the file "Index.aspx".
Copy ALL following codes to replace the content of the file "Index.aspx".
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="OnBarcodeReaderASPNETWebDemo.Index" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>OnBarcode Reader ASP.NET Web Demo</title> </head> <body> <form id="form1" runat="server" enctype="multipart/form-data"> <div style="text-align:center"> <br /><br /> <asp:FileUpload ID="FileUpload1" runat="server" /> Barcode Type: <asp:DropDownList ID="dropDownListBarcodeType" runat="server" AutoPostBack="true" /> <br /><br /> <asp:Button ID="UploadToScan" runat="server" Text="Scan Image" OnClick="UploadToScan_Click" /> <br /><br /> Scan Result: <br /> <asp:TextBox ID="ScanResult" runat="server" Text="" Width="500" Height="100" TextMode="MultiLine" ReadOnly="true" /> </div> </form> </body> </html>
Copy ALL following codes to replace the content in the file "Index.aspx.cs".
using System; using System.Collections.Generic; using System.IO; using System.Text; using OnBarcode.Barcode.BarcodeScanner; namespace OnBarcodeReaderASPNETWebDemo { public partial class Index : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { String[] types = new String[] { "AustraliaPost", "Codabar", "Code39", "Code39Extension", "Code93", "Code128", "DataMatrix", "EAN8", "EAN13", "Identcode", "IntelligentMail", "Interleaved2of5", "ISBN", "ISSN", "ITF14", "Leitcode", "PatchCode", "PDF417", "Planet", "Postnet", "QRCode", "RM4SCC", "UPCA", "UPCE" }; this.dropDownListBarcodeType.DataSource = types; this.dropDownListBarcodeType.DataBind(); // Default Barcode Type: Code 128 this.dropDownListBarcodeType.SelectedIndex = 5; } } protected void UploadToScan_Click(object sender, EventArgs e) { if (!this.FileUpload1.HasFile) return; try { String filename = Path.GetFileName(this.FileUpload1.FileName); StringBuilder sb = new StringBuilder(); using (MemoryStream ms = new MemoryStream(this.FileUpload1.FileBytes)) { // Get enum BarcodeType from ComboBox selected index. BarcodeType barcodeType = (BarcodeType)this.dropDownListBarcodeType.SelectedIndex; String[] result = BarcodeScanner.Scan(ms, barcodeType); if (result.Length > 0) { sb.Append("Number of Barcode: " + result.Length + "\r\n"); foreach (String s in result) sb.Append("Message: '" + s + "'\r\n"); } else { sb.Append("No Barcode Found."); } } this.ScanResult.Text = sb.ToString(); } catch (Exception ex) { this.ScanResult.Text = "Error: " + ex.Message; } } } }
4. Set Web.Config
Set start page to "Index.aspx" in Web.Config.
Copy contents in red to the Web.config file.
Copy contents in red to the Web.config file.
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit https://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.webServer> <defaultDocument> <files> <clear /> <add value="Index.aspx" /> </files> </defaultDocument> </system.webServer> </configuration>
5. Run barcode reader for ASP.NET Framework web form app
It is done. Now press "Ctrl+F5" to run the web project.
Use "Choose File" button to browse and add an image file with barcode(s).
Then, press "Scan Image" button to submit the form to server; and then the scan result would be shown in the scan result textbox as below.
Use "Choose File" button to browse and add an image file with barcode(s).
Then, press "Scan Image" button to submit the form to server; and then the scan result would be shown in the scan result textbox as below.
Common Asked Questions
How to enable barcode scanning functionality in an ASP.NET web form application?
To enable barcode scanning and reading functionality in an ASP.NET framework web site, you can build a new ASP.NET framework web project using Visual Studio,
add the C# barcode reader dll to the ASP.NET project reference, and use the following C# code to read barcode in your ASP.NET application.
BarcodeScanner.Scan().
What image formats are supported using C# Barcode Reader library?
Using C# Barcode Reader library, you can read and detect barcodes from multiple raster image formats, including jpg, png, bitmap, multi-page tiff image file
in your ASP.NET framwork web form application or website.
What barcode formats are supported in ASP.NET web application using C# Barcode library?
OnBarcode C# Barcode Reader library supports most of the common 2d and 1d barcodes scanning and recognition in ASP.NET web application.
2d barcodes include QR Code (ISO and GS1 standard), Data Matrix (ISO and GS1 standard), PDF417. 1d barcodes include
Code 128, Code 39, EAN/UPC with add-on symbols, GS1-128, ITF-14, Interleaved 2 of 5 and other linear barcode formats.
What platforms does C# Barcode Reader library support?
C# Barcode Reader library will work with your ASP.NET framework web application on Windows operating system with the following .NET environment installed.
- .NET Framework 4.x, 3.x, 2.x
- .NET Standard 2.0
- .NET 5+
- .NET Core 2.x, 3.x
Can I create barcodes in ASP.NET using C# Barcode Reader SDK API?
No. You cannot generate and print barcodes in ASP.NET web application using C# Barcode Reader library. It is for barcode scanning only.
However you can use OnBarcode C# Barcode Generator library in your ASP.NET application to create, and print barcodes.
Does C# Barcode Scanner library support decoding barcodes from video feeds in ASP.NET framework project?
Yes. C# Barcode Reader library supports to scan QR Code and barcodes from video feeds.
You can quickly create a real time image data processing web site and scan barcodes from video feeds in your ASP.NET framework web application.
How to get a trial license of C# Barcode Reader library?
You can directly download and install the free trial package from the website, and add the trial version dll to your ASP.NET project reference.
You can also download and install OnBarcode C# Barcode Reader library nuget package from NuGet Package Manager in Visual Studio.
How to customize barcode scanner in ASP.NET framework using C# Barcode Reader SDK?
You can easily customize the barcode scanner during barcode recognition in your ASP.NET framework web application using C# Barcode Reader library.
The barcode reader library allows you to adjust image scanning interval, barcode scanning directions, define barcode scanning specific areas and enable multi-thread barcode scanning
in C# ASP.NET framework web forms application.