Click here to Skip to main content
14,326,246 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear All,

I want to print bar codes from an application.I am using Zebra printer and i have created text files from my application below are the code to create text file
Using dr As SqlDataReader = cmd.ExecuteReader()

              Using StringWriter
                  While dr.Read()
                      Dim linex As String = "^FD>;" & dr.Item("BARCODEVALUE") & "^FS"
                  End While
              End Using
          End Using

This is working fine if i am typing from dos prompt
Type filename.txt >prn

Now i have created a function to print like below
Dim proc As New System.Diagnostics.Process
        With proc.StartInfo
            .FileName = "cmd.exe"
            .Arguments = _shellcmd
        End With


where _shellCmd is the command to call dos printing
Dim shellcommand As String = "/C copy " & barcodefile + " lpt1"

this all working from dev server,but after publishing when i press the button nothing happend.I published the site in the same system where the printer is installed and add Defaultpool users to the printer and gave permission to print but still nothing happening.Please help

What I have tried:

Created the barcode text file and it printed from application which is in development stage
Updated 8-Oct-19 8:09am
Rate this:
Please Sign up or sign in to vote.

Solution 1

We can't really tell, but there are a couple of things you can look at.
1) VB code is executed on the Server, not the client - I assume that the printer is installed on the Server because you can't access client computers from VB.
2) On the server, the site runs as part of IIS, which does not run under a "normal" user account - it normally runs under the Network Services account so you will need to ensure that the folder holding your print file is accessible to that and the printer driver - I'd recommend using a specific folder which is read-write for all users (this is almost certainly not the case for IIS website folders)
3) If it works when you type it to prn then why are you using a different port to print - lpt - change one variable at a time, not multiple!
Rate this:
Please Sign up or sign in to vote.

Solution 2

Rather than shelling out to a DOS command, you can use code to send the ZPL directly to the printer. Here's the class I use to do that:
Raw printer helper · GitHub[^]

It's in C#, but you can either convert it, or compile it into a library and call it from your VB.NET code.
RawPrinterHelper.SendStringToPrinter("Name of the printer to use", zplStringToPrint, "My barcode")

As Griff said, this code is running on the server, so you'll need to make sure the ZPL printer is installed on the server, and accessible to the IIS account.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100