Thanks for downloading Dynamsoft Barcode Reader Package!
Your download will start shortly. If your download does not begin, click here to retry.
In this guide, you will learn step by step on how to build a barcode reading application with Dynamsoft Barcode Reader SDK using .Net.
If you haven’t downloaded the SDK yet, download the .NET Package
now from Dynamsoft website and unpack the package into the directory of your choice.
For this tutorial, we unpack it to
[INSTALLATION FOLDER]
, change it to your unpacking path for the following content.
After you unzip the file, you can find samples for supported platforms in the Samples folder under the installation folder.
The .NET SDK is developed based on .NET Framework 2.0/4.0. If you are using .NET Core 3.1 or 5.0, please download the .NET Core SDK (Dynamsoft.NetCoreApp.Barcode) from Here.
Let’s start by creating a console application which demonstrates how to use the minimum code to read barcodes from an image file.
You can download the entire source code and compiled program from Here.
DBRCSharpSample
.[INSTALLATION FOLDER]\Lib\4.0
and Select Dynamsoft.BarcodeReader.dll
and DynamsoftCommon.dll
.
Browse to
[INSTALLATION FOLDER]\Lib\2.0
if you want to use .NET Framework 2.0.
Dynamsoft.DotNet.Barcode
.Program.cs
.
using Dynamsoft;
using Dynamsoft.DBR;
Create an instance of Dynamsoft Barcode Reader.
BarcodeReader reader = new BarcodeReader("<insert DBR license key here>")
Please replace
<insert DBR license key here>
with a valid DBR licensekey. There are two ways to obtain one:
- Search
DBRLicense
and find the license from[INSTALLATION FOLDER]\Samples\BarcodeReaderDemo\BarcodeReaderDemo\App.config
.- Request a trial license from Customer Portal.
Set barcode format and count to read.
PublicRuntimeSettings runtimeSettings = reader.GetRuntimeSettings();
runtimeSettings.BarcodeFormatIds = (int)EnumBarcodeFormat.BF_ALL;
runtimeSettings.BarcodeFormatIds_2 = (int)(EnumBarcodeFormat_2.BF2_POSTALCODE | EnumBarcodeFormat_2.BF2_DOTCODE);
runtimeSettings.ExpectedBarcodesCount = 32;
reader.UpdateRuntimeSettings(runtimeSettings);
The barcode formats to enable is highly application-specific. We recommend that you only enable the barcode formats your application requires. Check out Barcode Format Enumeration for full supported barcode formats.
If you know exactly the barcode count you want to read, specify
ExpectedBarcodesCount
to speed up the process and improve the accuracy.
Get and output barcode results.
TextResult[] results;
try
{
results = reader.DecodeFile(@"[INSTALLATION FOLDER]/Images/AllSupportedBarcodeTypes.png", "");
Console.WriteLine("Total barcodes found: " + results.Length);
for (int iIndex = 0; iIndex < results.Length; ++iIndex)
{
Console.WriteLine("Barcode " + (iIndex + 1));
if (results[iIndex].BarcodeFormat != 0)
{
Console.WriteLine(" Barcode Format: " + results[iIndex].BarcodeFormatString);
}
else
{
Console.WriteLine(" Barcode Format: " + results[iIndex].BarcodeFormatString_2);
}
Console.WriteLine(" Barcode Text: " + results[iIndex].BarcodeText);
}
}
catch (BarcodeReaderException exp)
{
Console.WriteLine(exp.Message);
}
For the error handling mechanism, the SDK throws BarcodeReaderException for each function. You should add codes for exception handling based on your needs.
The SDK returns multiple barcode information, including barcode count, barcode format, barcode text, location, barcode raw data, etc. Check out TextResult for full supported result data.
Destroy the instance to release all resources.
reader.Dispose();
Note:
Please change all[INSTALLATION FOLDER]
in above code snippet to your unpacking path.
In Visual Studio, build the project to generate program DBRCSharpSample.exe
.
Run the program DBRCSharpSample.exe
.
If you got the exception “Failed to create compression directory” or “Failed to load module dll”, please copy
x64
andx86
folders to the folder whereDynamsoft.BarcodeReader.dll
andDynamsoftCommon.dll
resides and try again. Thex64
andx86
folders can be found under[INSTALLATION FOLDER]\Lib\2.0
or[INSTALLATION FOLDER]\Lib\4.0
.
You can download the entire source code and compiled program from Here.
latest version