Hello, Ukamani,
Could you please tell me if you were able to print a label from C#? My job seems to be sending, but the output is blank. I've attached the settings and code.
using System; using System.IO; using System.Net.Sockets; using System.Text; class Program { static void Main(string args) { string printerIp = "10.118.4.200"; // Replace with your printer's IP address int port = 9100; //3001 // Example ZPL code to print a simple label string zplCode = "^XA^FO10,10^A0N,100,100^FDhello World^FS^XZ"; // End Format try { SendZplToPrinter(printerIp, port, zplCode); Console.WriteLine("ZPL code sent successfully!"); } catch (Exception ex) { Console.WriteLine($"An error occurred: {ex.Message}"); } Console.ReadKey(); } static void SendZplToPrinter(string ipAddress, int port, string zplData) { using (TcpClient client = new TcpClient()) { // Connect to the printer client.Connect(ipAddress, port); // Get a stream for writing data using (NetworkStream stream = client.GetStream()) { // Convert the ZPL string to bytes byte[] bytes = Encoding.ASCII.GetBytes(zplData); // Send the bytes to the printer stream.Write(bytes, 0, bytes.Length); } } } }
