chris bahr
chris bahr

Reputation: 165

Printing a .ZPL file to a zebra printer in vb.net. Visual Studio 2015 version

I already have the raw ZPL file ready to go, I just don't know how to set the printer I want to send it to and then send it. How would I do this?

Note: I have a batch script on my computer that I default all ZPL files to, which is a shell script that sends the file to the thermal printer on my computer. I want to get away from that and have all the commands within my application so I don't have to use an external script like that.

This is the code I have now that when ran it auto opens with my batch script:

 Sub SaveLabel(ByRef labelFileName As String, ByRef labelBuffer() As Byte)
        ' Save label buffer to file
        Dim myPrinter As New PrinterSettings
        Dim LabelFile As FileStream = New FileStream(labelFileName, FileMode.Create)
        LabelFile.Write(labelBuffer, 0, labelBuffer.Length)
        LabelFile.Close()
        ' Display label
        DisplayLabel(labelFileName)
    End Sub

    Sub DisplayLabel(ByRef labelFileName As String)
        Dim info As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo(labelFileName)
        info.UseShellExecute = True
        info.Verb = "open"
        info.WindowStyle = ProcessWindowStyle.Hidden
        info.CreateNoWindow = True
        System.Diagnostics.Process.Start(info)
    End Sub

And this is my batch script:

copy %1 \\%ComputerName%\Zebra

Upvotes: 0

Views: 6234

Answers (1)

theB
theB

Reputation: 6738

To replicate the exact functionality of the batch file in VB.net:

Dim filename As String = System.IO.Path.GetFileName(labelFileName)
System.IO.File.Copy(
                labelFileName,
                Environment.ExpandEnvironmentVariables("\\%ComputerName%\Zebra\" & filename))

This copies the file using the method provided by the System.IO namespace. It also expands the %COMPUTERNAME% environment variable. This replaces all the code in the DisplayFile subroutine.

Upvotes: 1

Related Questions