How to Generate a UPC-A Barcode in C# .NET Framework
We’ll always need barcode images to ship products, and if we’re located in the United States, we’ll need UPC-A. Thankfully, we can generate UPC-A barcode images at low cost with a low-code API solution.
Using the below code, we can take advantage of a free API that’ll generate PNG barcode images out of our UPC-A barcode values in a quick operation. All we need is a free API key, and we can make this conversion up to 800 times per month with no additional commitments (once we reach our limit, it’ll just reset the following month).
To get started, let’s install the SDK. We can run the below command in our Package Manager console to install via NuGet:
Install-Package Cloudmersive.APIClient.NET.Barcode -Version 3.0.2
Next & last on our list, let’s call the function. This part is easy — we can just copy the below code into our file and then include our API key & barcode values:
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;
using Cloudmersive.APIClient.NET.Barcode.Model;
namespace Example
{
public class GenerateBarcodeUPCAExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new GenerateBarcodeApi();
var value = value_example; // string | UPC-A barcode value to generate from
try
{
// Generate a UPC-A code barcode as PNG file
byte[] result = apiInstance.GenerateBarcodeUPCA(value);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling GenerateBarcodeApi.GenerateBarcodeUPCA: " + e.Message );
}
}
}
}
Just like that, we’re all done; no more code required, and we can now generate hundreds of UPC-A barcode images at zero cost.