C# Generate Barcode from String: Complete Tutorial with IronBarcode
Encoding string data into barcode images is a fundamental requirement for inventory systems, retail applications, and document management. This tutorial demonstrates how to generate barcode from string values in C# using IronBarcode, covering everything from installation to saving barcode images in multiple formats.
IronBarcode is a .NET library developed by Iron Software that simplifies barcode generation and reading for .NET developers building Windows applications and web services. Start your free trial to follow along with the code examples below.
How Do I Install a Barcode Library in Visual Studio?
Installing IronBarcode takes seconds using NuGet Package Manager. Open Visual Studio, navigate to Tools > NuGet Package Manager > Package Manager Console, and run:
Install-Package BarCode
Alternatively, search for "IronBarCode" in the NuGet Package Manager GUI and install the official IronBarcode package. The library supports .NET Framework 4.6.2+ and .NET Core/.NET 5+, ensuring compatibility across modern .NET applications.
How Can I Generate a Simple Barcode from a String?
The BarcodeWriter.CreateBarcode method is the core of IronBarcode's barcode generation functionality. This fluent API accepts your string data and the desired encoding format, then outputs a GeneratedBarcode object ready for saving.
using IronBarCode;
// C# generate barcode from string with a single method call
string productCode = "SKU-78432-A";
var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);
barcode.SaveAsPng("product_barcode.png");using IronBarCode;
// C# generate barcode from string with a single method call
string productCode = "SKU-78432-A";
var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);
barcode.SaveAsPng("product_barcode.png");IRON VB CONVERTER ERROR developers@ironsoftware.comBarcode Generation Output

This source code creates a Code128 barcode image from the product string and saves it as a PNG file. The CreateBarcode method handles all the encoding complexity, allowing you to generate barcode images with minimal code. IronBarcode supports saving to multiple image file formats including PNG, JPEG, GIF, TIFF, and BMP.
The method also accepts optional width and height parameters to control the output dimensions, helping ensure proper scanning in your target environment.
What Barcode Formats Does IronBarcode Support?
IronBarcode supports a comprehensive range of barcode types for different use cases. Understanding which format to use helps ensure proper scanning and data capacity for your application.
using IronBarCode;
string data = "https://ironsoftware.com";
string numericId = "0123456789012";
// Generate QR Code for URLs and text data
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.QRCode).SaveAsPng("qrcode.png");
// Generate UPC-A for retail products (12 digits)
BarcodeWriter.CreateBarcode(numericId, BarcodeEncoding.UPCA).SaveAsPng("upc_barcode.png");
// Generate PDF417 for documents requiring more data capacity
BarcodeWriter.CreateBarcode("Extended product details here", BarcodeEncoding.PDF417)
.SaveAsJpeg("pdf417_barcode.jpeg");using IronBarCode;
string data = "https://ironsoftware.com";
string numericId = "0123456789012";
// Generate QR Code for URLs and text data
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.QRCode).SaveAsPng("qrcode.png");
// Generate UPC-A for retail products (12 digits)
BarcodeWriter.CreateBarcode(numericId, BarcodeEncoding.UPCA).SaveAsPng("upc_barcode.png");
// Generate PDF417 for documents requiring more data capacity
BarcodeWriter.CreateBarcode("Extended product details here", BarcodeEncoding.PDF417)
.SaveAsJpeg("pdf417_barcode.jpeg");IRON VB CONVERTER ERROR developers@ironsoftware.comBarcode Image Outputs

Here's when to use each format:
- QR Code: Best for URLs, text data, and mobile scanning applications. Supports ASCII and Unicode characters.
- Code128: Ideal for alphanumeric product codes and shipping labels. Offers high data density.
- UPC/EAN: Required for retail point-of-sale systems. Numeric-only with fixed lengths.
- PDF417: Suitable for ID cards and documents needing additional information storage.
IronBarcode supports over 20 barcode formats, giving .NET developers flexibility for virtually any barcode generation requirement.
How Can I Customize and Style Barcode Images?
Beyond basic barcode generation, IronBarcode provides advanced styling options through its fluent API. You can adjust colors, add annotations, and resize barcode images using built-in styling methods.
using IronBarCode;
using IronSoftware.Drawing;
string orderNumber = "ORD-2024-00542";
var styledBarcode = BarcodeWriter.CreateBarcode(orderNumber, BarcodeEncoding.Code128);
// Adjust colors for branding
styledBarcode.ChangeBarCodeColor(Color.DarkBlue);
styledBarcode.ChangeBackgroundColor(Color.White);
// Add text annotations
styledBarcode.AddAnnotationTextAboveBarcode("Order Number", new Font("Arial", 12), Color.Black, 5);
styledBarcode.AddBarcodeValueTextBelowBarcode(new Font("Arial", 10), Color.Gray, 5);
// Resize and save
styledBarcode.ResizeTo(400, 150);
styledBarcode.SaveAsPng("styled_order_barcode.png");using IronBarCode;
using IronSoftware.Drawing;
string orderNumber = "ORD-2024-00542";
var styledBarcode = BarcodeWriter.CreateBarcode(orderNumber, BarcodeEncoding.Code128);
// Adjust colors for branding
styledBarcode.ChangeBarCodeColor(Color.DarkBlue);
styledBarcode.ChangeBackgroundColor(Color.White);
// Add text annotations
styledBarcode.AddAnnotationTextAboveBarcode("Order Number", new Font("Arial", 12), Color.Black, 5);
styledBarcode.AddBarcodeValueTextBelowBarcode(new Font("Arial", 10), Color.Gray, 5);
// Resize and save
styledBarcode.ResizeTo(400, 150);
styledBarcode.SaveAsPng("styled_order_barcode.png");IRON VB CONVERTER ERROR developers@ironsoftware.comStyled Barcode Output

The styling methods chain together naturally, making it easy to create barcode images that match your application's visual design while maintaining scannability. Learn more about customizing barcode styles in the documentation.
How Do I Generate Multiple Barcodes in C# from Database Data?
Real-world applications often require barcode generation for multiple items from a database or data collection. IronBarcode handles batch processing efficiently.
using IronBarCode;
// Simulated data from database query
List<string> productIds = new List<string>
{
"PROD-001-X",
"PROD-002-Y",
"PROD-003-Z",
"PROD-004-W"
};
// Generate multiple barcodes from the data collection
foreach (var productId in productIds)
{
var barcode = BarcodeWriter.CreateBarcode(productId, BarcodeEncoding.Code128, 300, 100);
barcode.SaveAsPng($"barcodes/{productId}.png");
}using IronBarCode;
// Simulated data from database query
List<string> productIds = new List<string>
{
"PROD-001-X",
"PROD-002-Y",
"PROD-003-Z",
"PROD-004-W"
};
// Generate multiple barcodes from the data collection
foreach (var productId in productIds)
{
var barcode = BarcodeWriter.CreateBarcode(productId, BarcodeEncoding.Code128, 300, 100);
barcode.SaveAsPng($"barcodes/{productId}.png");
}IRON VB CONVERTER ERROR developers@ironsoftware.comOutput Barcodes

This process scales easily to thousands of records. For high-volume barcode generation, IronBarcode also supports async and multithreaded operations to maximize throughput.
The generated barcode images can be embedded in reports, printed on labels, or stored for later use. Each image file maintains the encoded binary data that scanners read to retrieve the original string value.
Conclusion
Generating barcode from string data in C# is straightforward with IronBarcode. The library's fluent API handles the complexity of barcode encoding while providing flexibility for customization and batch processing. Whether you need simple Code128 barcodes for inventory or QR codes for mobile applications, IronBarcode delivers reliable barcode functionality for .NET applications.
Ready to add barcode generation to your project? Download IronBarcode or purchase a license for production deployment. The library includes comprehensive documentation and code examples to accelerate your development.
Frequently Asked Questions
How do I install IronBarcode for generating barcodes in C#?
To install IronBarcode, you can use NuGet Package Manager in Visual Studio. Simply search for 'IronBarcode' and click install to add it to your project.
What barcode formats can I generate from a string using IronBarcode?
IronBarcode supports a variety of barcode formats including QR Code, Code 128, UPC, and more, allowing you to generate the format that best suits your needs.
Can I customize the appearance of barcodes generated with IronBarcode?
Yes, IronBarcode allows you to style your barcodes with custom colors, label fonts, and sizes to match your application’s branding.
Is batch processing of barcodes supported in IronBarcode?
IronBarcode supports batch processing, making it easy to generate multiple barcodes in one operation, which is perfect for large datasets.
Can IronBarcode save generated barcodes in different image formats?
Yes, you can save barcodes generated with IronBarcode in various image formats such as JPEG, PNG, and GIF.
How do I encode a string into a barcode using IronBarcode?
To encode a string into a barcode, simply use IronBarcode's BarcodeWriter class, specifying the string and desired barcode format.
What are the system requirements for using IronBarcode in a C# project?
IronBarcode is compatible with .NET Framework and .NET Core, and it requires Visual Studio for development.
Does IronBarcode provide error correction features?
Yes, IronBarcode includes error correction capabilities, ensuring that barcodes are readable even if they are partially damaged.
Can IronBarcode be used in web applications?
IronBarcode can be integrated into both desktop and web applications, making it a versatile choice for developers.
Is there a trial version available for IronBarcode?
IronBarcode offers a free trial version which allows you to test its features before committing to a purchase.








