DEVELOPERS / C# / ZPL

Print ZPL Labels From C# and .NET

Two ways to print labels from C#: raw ZPL over TcpClient to port 9100, or the LabelInn .NET SDK — print to any printer from any server, with queueing, status and templates.

FREE PLAN · NO CREDIT CARD · WINDOWS / MAC / ANDROID / WEB

THE PROBLEM

An operator printing a label on an industrial printer at the line

You need C# code to put a label on a thermal printer: a shipping label when an order is paid, a product label when a batch is finished. There are two ways to do it. This page shows both, with code you can paste.

01 / C#

The quick way: raw ZPL to port 9100

Zebra printers, and most printers that emulate ZPL, accept raw ZPL on TCP port 9100. If your code runs on the same network as the printer, this is all it takes:

EXAMPLEC#
using System.Net.Sockets;
using System.Text;

var zpl = "^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ";

using var tcp = new TcpClient();
await tcp.ConnectAsync("192.168.1.50", 9100);
await tcp.GetStream().WriteAsync(Encoding.UTF8.GetBytes(zpl));

02 / ZPL

Why not just open a socket?

Writing ZPL to port 9100 works on the bench. In production it leaves you with problems the printer will not solve for you:

  • Your server has to reach the printer. A cloud-hosted C# app cannot open a socket to a printer on a warehouse LAN without a VPN or port forwarding.
  • Nothing tells you it printed. Port 9100 accepts the bytes whether or not the ribbon is out or the head is open.
  • Nothing queues. If the printer is off, the job is gone.
  • One language per printer. ZPL works on Zebra; TSC wants TSPL, Toshiba wants TPCL.

LabelInn puts a small runtime next to the printer that connects out to the cloud. Your code calls one HTTPS API from anywhere; the job is queued, delivered in the printer's own language, and its status comes back.

dotnet add package LabelInn, one API key, and your C# code prints to any registered printer, anywhere. Get a key →

03 / ZEBRA

Install the SDK

EXAMPLESHELL
dotnet add package LabelInn

04 / API

Find the printer

Register the printer once in the LabelInn app on the computer it is connected to. Then list your printers to get the id:

EXAMPLEC#
using LabelInn;

using var client = new LabelInnClient("sk_live_...");

foreach (var p in await client.Fleet.ListAsync())
    Console.WriteLine($"{p.Id} {p.Name} {p.Status}");

05 / C#

Print ZPL

EXAMPLEC#
var job = await client.Print.CreateAsync(new CreateJobRequest
{
    PrinterId = "prt_abc123",
    PayloadType = "zpl",
    PayloadData = "^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ",
});
Console.WriteLine($"{job.Id} {job.Status}");

06 / ZPL

Print a designed label with data

Raw ZPL means your code owns the layout. With a template, the label is designed visually in LabelInn and your code sends only the data. Fields fill by name, and LabelInn converts the design to ZPL, TSPL or TPCL for whichever printer you choose.

EXAMPLEC#
var job = await client.Print.CreateAsync(new CreateJobRequest
{
    PrinterId = "prt_abc123",
    PayloadType = "template",
    DesignId = "dsg_shipping",
    Data = new { order_id = "ORD-9876", customer = "Jane Doe", barcode = "TR123456789" },
    Copies = 2,
});

07 / ZEBRA

Print many labels in one call

Batch up to 100 jobs per request. Each job is accepted or rejected on its own, so one bad row does not sink the rest.

EXAMPLEC#
var skus = new[] { "A-1001", "A-1002", "A-1003" };
var result = await client.Print.BatchAsync(skus.Select(sku => new CreateJobRequest
{
    PrinterId = "prt_abc123",
    PayloadType = "template",
    DesignId = "dsg_product",
    Data = new { sku },
}));
Console.WriteLine($"{result.Succeeded} of {result.Total} accepted");

08 / API

Never print the same label twice

Retries happen: a timeout, a redeploy, a queue redelivery. Send an idempotency key and a repeated call returns the original job instead of printing again.

EXAMPLEC#
var job = await client.Print.CreateAsync(new CreateJobRequest
{
    PrinterId = "prt_abc123",
    PayloadType = "template",
    DesignId = "dsg_shipping",
    Data = new { order_id = "ORD-9876" },
}, idempotencyKey: "order-ORD-9876-label");

Printing through the API is part of the Pro plan, and the free trial includes it. Keys that start with sk_test_ run against a sandbox that never prints, so you can build and test before going live. See pricing.

TESTED

What was run for this page

Environment

The snippets on this page were run on 17 October 2026 against a local mock of the API (the official SDK, installed from its package registry) and a local listener standing in for port 9100. They prove the request shape and the code compiles and runs; they do not prove a physical print.

.NET 8 SDK and the LabelInn 3.1.0 NuGet package. The SDK sent User-Agent: labelinn-csharp/3.1.0; BatchAsync returned Succeeded 3 of Total 3; the idempotent call carried X-Idempotency-Key.

SDK factValue (checked 17 October 2026)
PackageLabelInn 3.1.0 on NuGet (dotnet add package LabelInn)
Targetsnet6.0 and net8.0; no external dependencies, built on HttpClient
LifetimeLabelInnClient is IDisposable: create one and reuse it, as with HttpClient
Base URLSecond constructor argument, e.g. new LabelInnClient("sk_test_...", "http://localhost:8080/v1")

C#-SPECIFIC

StreamWriter(Encoding.UTF8) puts three bytes in front of ^XA

EXAMPLECSHARP
// writes EF BB BF before ^XA: a UTF-8 byte order mark
using var w = new StreamWriter(stream, Encoding.UTF8);

// no BOM: either of these
var bytes = Encoding.UTF8.GetBytes(zpl);
using var w2 = new StreamWriter(stream, new UTF8Encoding(false));

Measured on .NET 8: Encoding.UTF8.GetBytes(zpl) starts 5E 58 41 5E (^XA^); a StreamWriter created with Encoding.UTF8 starts EF BB BF 5E. The printer sees those three bytes before the label. The snippet on this page uses GetBytes, which is why it is safe.

ERRORS

Rate limits and API errors in the SDK

EXAMPLECSHARP
try
{
    await client.Print.CreateAsync(new CreateJobRequest { PrinterId = "prt_abc123", PayloadType = "zpl", PayloadData = "^XA^XZ" });
}
catch (LabelInnRateLimitException e)   // HTTP 429
{
    await Task.Delay(TimeSpan.FromSeconds(e.RetryAfterSeconds));
}
catch (LabelInnException e)            // any other API error
{
    Console.WriteLine($"{e.Status} {e.Code} {e.Message}");
}

Tested against a mock returning 429 BURST_RATE_LIMIT (printed RetryAfterSeconds=7) and 400 INVALID_PRINTER. Catch the rate-limit exception first: it derives from LabelInnException.

QUESTIONS / FAQ

Frequently asked questions

How do I print a ZPL label from C#?

On the same network, write the ZPL to the printer's TCP port 9100. From anywhere else, install the LabelInn SDK, register the printer once, and call print.create with payload_type "zpl" and the printer id.

Can my cloud-hosted C# app print to a printer in a warehouse?

Yes. The LabelInn runtime next to the printer connects out to LabelInn, so your server calls an HTTPS API and never needs network access to the printer itself.

Does it only work with Zebra printers?

No. Raw ZPL needs a ZPL printer, but templates are converted to the printer's own language, including TSPL for TSC and TPCL for Toshiba.

How do I avoid printing duplicates when a request is retried?

Send an idempotency key with the job. Repeating the call with the same key returns the original job instead of printing again.

Why does my label print garbage before it starts from C#?

A StreamWriter made with Encoding.UTF8 writes a byte order mark (EF BB BF) first. Use Encoding.UTF8.GetBytes or new UTF8Encoding(false).

Which .NET versions does the LabelInn package support?

It targets net6.0 and net8.0 and has no external dependencies.

NEXT STEP / LABELINN

Print from C# without touching a printer driver

Get an API key, register a printer, and send your first label in minutes. · Official SDK · ZPL or visual templates · Queue, status and retries handled

Start free →