Search code examples
asp.netzpl

Converting byte[] to zpl format


I am accessing the shipping APIs and getting label information back in a byte[] format.

If I save this as a file, opening the file reveals the beautiful data that I need.

I have been saving this file like this:

 string LabelPath = "c:\\temp\\";
 string LabelFileName = LabelPath + "trackingnumber" + ".zpl";

 FileStream LabelFile = new FileStream(LabelFileName, FileMode.Create);
 LabelFile.Write(Label.Parts[0].Image, 0, Label.Parts[0].Image.Length);
 LabelFile.Close();

I want to be able to do whatever conversion this file saving is doing to be able to pass the information as pure data. The data on file renders something like this:

^FO28,962^A0N,27,32^FWN^FH^FD## MASTER ## ^FS
^FO136,874^A0N,27,36^FWN^FH^FD1 of 2^FS
^FO32,253^AdN,0,0^FWN^FH^FDLouisville KY 40218^FS

This is what I have tried and it does convert successfully to a string but it doesn't look anything like I need it to. It's just a long string that our Zebra printer does not know how to handle.

LabelStream = Convert.ToBase64String(Label.Parts[0].Image)

How do I do the same kind of conversion that the LabelFile.Write is doing without having to actually save a file?


Solution

  • It looks your data is not base64, but plain text? Maybe you can try this?

    LabelStream = Encoding.Default.GetString(Label.Parts[0].Image)