Simple to generate QR Code barcode images in ASP.NET web using C# class library
Quick to create QR Code barcode on a web page by dragging ASP.NET Barcode DLL
Able to control QR Code barcode image properties through ASP.NET Barcode Controller
Able to use C# code to set QR Code barcode image data mode, ECL, version, color & size
All encoded ASP.NET QR Code barcode images are compatible with QR Code industrial specifications
ASP.NET C# QR Code Barcode Generation - Requirement
BarcodeLib.Barcode.Common.dll
.NET 5+
Visual Studio .NET 2005 or greater
ASP.NET Framework Web Controller - C# QR Code Generation
Unzip Barcode for ASP.NET trial package and you will find BarcodeLib.Barcode.ASP.NET.dll. Then do as follows:
Add it to your ASP.NET C# project Toolbox.
Right click Toolbox, select Choose Items..., switch to .NET Framework Components tab, and locate BarcodeLib.Barcode.ASP.NET.dll. Then, you'll find four components, including QRCodeASPNET.
Under barcode folder of the trial package, copy files "qrcode.aspx", "qrcode.aspx.cs" to your created ASP.NET project folder where the barcode images will be generated.
Drag QRCodeASPNET to aspx page and then run the project to see the generated QR Code image. And this QR Code barcode properties are all in default values.
If you want to customize the QR Code image properties, you may directly set in the Properties window or using the C# code like below.
ASP.NET Class - C# QR Code Barcode Image Generation
Add BarcodeLib.Barcode.ASP.NET.dll to your ASP.NET C# project Reference.
In Solution Explorer window, right click on your project, select Add Reference..., switch to Browse tab and find BarcodeLib.Barcode.ASP.NET.dll.
Then, please use the following Visual C# sample code to generate QR Code for your ASP.NET application.
QRCode qrcode = new QRCode();
qrcode.Data = "www.barcodelib.com";
qrcode.ModuleSize = 4;
qrcode.ECL = QRCodeErrorCorrectionLevel.L;
qrcode.ImageHeight = 118;
qrcode.ImageWidth = 118;
// Save QR Code barcode image into your system
qrcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;
qrcode.drawBarcode("C:/sample-qrcode.gif");
In the following tutorial, we'll show step by step how to build a new ASP.NET Core (Razor Pages) web app, and integrate online barcode generating feature on ASP.NET web page using C# codes.
Step 1. Create a new ASP.NET Core web app
Here we will quickly create a new ASP.NET Core Razor Pages web project in Visual Studio.
Start Visual Studio 2022 and select Create a new project
In the Create a new project dialog, select ASP.NET Core Web App (Razor Pages) for the project template, and click button Next.
In the Configure your new project dialog, enter BarcodeLib.QRCodeGenerator.AspNetCore.Demo for Project name.
It is important to
name the proejct BarcodeLib.QRCodeGenerator.AspNetCore.Demo, including letter case, so the namespaces will match when you copy, paste the following C# example code.
Click Next
In the Additional information diaplog, select .NET 8.0 (Long Term Support) for the Framework dropdowns. Click button Create.
Now we have created a new ASP.NET Core Razor Page web project successfully.
Step 2. Install QR Code Generator library and Nuget package
Now we will add BarcodeLib barcode generator library to the ASP.NET Core web project and also add a Nuget package named System.Drawing.Common.
Add BarcodeLib Barcode Generator library
In the Solution Explorer window, right click Dependencies, select Add Project Reference...
Select button Browse... in the Reference Manager dialog.
Choose dll file BarcodeLib.Barcode.Common.dll from BarcodeLib downloaded package /Dll/net-standard/
Check BarcodeLib.Barcode.Common.dll is selected, and select button OK
Now we have added the barcodelib QR Code generator library dll. We will start to add a library System.Drawing.Common from NuGet
Install NuGet Package
Right click Dependencies, select Manage NuGet Packages...
Navigate to tab Browse in the NuGet Package Manager
Enter System.Drawing.Common to search NuGet package
Choose the first searched result System.Drawing.Common by Microsoft
Select button Install
Now we have installed the barcode generator library and nuget package successfully.
For ASP.NET Core web app on Linux, MacOC ....
The above BarcodeLib barcode library and NuGet package is for ASP.NET web app running on Windows operating systems.
If you will run ASP.NET web app on non-Windows operating systems, such as Linux, MacOS, you need install the following library dll
and NuGet package.
BarcodeLib.Barcode.SkiaSharp.dll from BarcodeLib downloaded package /Dll/net-standard/
SkiaSharp by Microsoft from NuGet Package Manager
Step 3. Add C# code to create barcode on a Razor Page
Copy the following code to file "Index.cshtml"
@page
@model IndexModel
@{
ViewData["Title"] = "BarcodeLib ASP.NET Core QR Code Generator Web Application";
}
<divclass="text-center">
<formasp-page="./Index"method="post">
<br />
QR Code data:
<inputtype="text"id="tb1"name="tbQRCodeData"style="width: 600px; "asp-for="@Model.QRCodeData" />
<br />
<br />
<inputtype="submit"value="Generate QR Code" />
</form>
<br />
<imgsrc="data:image/png;base64,@Model.QRCodeImage" />
</div>
Copy the following C# code to file "Index.cshtml.cs"
Now you have completed the demo app. Run the ASP.NET Core web app directly from Visual Studio. You can generate Code 128 barcodes online by entering Code 128 data online.