Click here to Skip to main content
15,883,957 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I want to print bar codes from an asp.net 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
                  StringWriter.WriteLine("CT~~CD,~CC^~CT~")
                  StringWriter.WriteLine("^XA~TA000~JSN^LT0^MNW^MTD^PON^PMN^LH0,0^JMA^PR2,2~SD15^JUS^LRN^CI0^XZ")
                  While dr.Read()
                      Dim linex As String = "^FD>;" & dr.Item("BARCODEVALUE") & "^FS"
                      StringWriter.WriteLine("^XA")
                      StringWriter.WriteLine("^MMT")
                      StringWriter.WriteLine("^PW406")
                      StringWriter.WriteLine("^LL0203")
                      StringWriter.WriteLine("^LS0")
                      StringWriter.WriteLine("^BY3,3,82^FT51,113^BCN,,Y,N")
                      StringWriter.WriteLine(linex)
                      StringWriter.WriteLine("^PQ1,0,1,Y^XZ")
                  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

        proc.Start()

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 asp.net application which is in development stage
Posted
Updated 8-Oct-19 8:09am
v2

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!
 
Share this answer
 
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.
VB.NET
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900