In the following step by step tutorial, we'll show you how to quickly create a new ASP.NET Core web app, and integrate online barcode generating feature on ASP.NET web page using C# codes.
1. Create a new ASP.NET Core web app
Here we will quickly create a new ASP.NET Core web app using Visual Studio .NET
Start Visual Studio and select Create a new project
In the Create a new project dialog, select ASP.NET Core Web App, and select button Next.
In the Configure your new project dialog, enter BarcodeLib.Create.ASPNETCoreDemo for Project name. It is important to
name the proejct BarcodeLib.Create.ASPNETCoreDemo, including letter case, so the namespaces will match when you copy, paste the following
C# example code.
Select button Create
In the Additional information diaplog, select .NET 6.0 or .NET 7.0 for the Framework dropdowns. Select button Create.
Now we have created a new ASP.NET Core project successfully.
2. Install Barcode Generator library and Nuget package
Now we will add BarcodeLib barcode generator library to the asp.net 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 barcode 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
3. Add C# code to create barcode on a Razor Page
Copy the following code to file "Index.cshtml"
@page@modelIndexModel@{ViewData["Title"]="BarcodeLib ASP.NET Core Barcode Generator";}<divclass="text-center"><formasp-page="./Index"method="post"><br/>Barcodedata:<inputtype="text"id="tb1"name="tbBarcodeData"style="width: 600px; "asp-for="@Model.BarcodeData"/><br/><br/><inputtype="submit"value="Create Barcode"/></form><br/><imgsrc="data:image/png;base64,@Model.BarcodeImage"/></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.
5. Customize the demo web app
You can easily customize the demo ASP.NET Core web app. For example, you can update the C# code inside method getBarcodeInBytes() to create QR Code online.