0

我已经准备好原始 ZPL 文件了,只是不知道如何设置要发送到的打印机,然后再发送。我该怎么做?

注意:我的计算机上有一个批处理脚本,我默认所有 ZPL 文件都使用它,这是一个将文件发送到我计算机上的热敏打印机的 shell 脚本。我想摆脱这种情况并在我的应用程序中拥有所有命令,这样我就不必使用这样的外部脚本。

这是我现在拥有的代码,当它运行时会使用我的批处理脚本自动打开:

 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

这是我的批处理脚本:

copy %1 \\%ComputerName%\Zebra
4

1 回答 1

1

要在 VB.net 中复制批处理文件的确切功能:

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

这将使用命名空间提供的方法复制文件System.IO。它还扩展了%COMPUTERNAME%环境变量。这将替换DisplayFile子例程中的所有代码。

于 2015-10-21T15:34:38.307 回答