Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
string command = "^XA^FO10,10,^AO,30,20^FDFDTesting^FS^FO10,30^BY3^BCN,100,Y,N,N^FDTesting^FS^XZ";

// Create a buffer with the command
Byte[] buffer = new byte[command.Length];
buffer = System.Text.Encoding.ASCII.GetBytes(command);
// Use the CreateFile external func to connect to the LPT1 port
SafeFileHandle printer = CreateFile("LPT1:", FileAccess.ReadWrite, 0, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
// Aqui verifico se a impressora é válida
if (printer.IsInvalid == true)
{
return;
}

/// Open the filestream to the lpt1 port and send the command
FileStream lpt1 = new FileStream(printer, FileAccess.ReadWrite);
lpt1.Write(buffer, 0, buffer.Length);
// Close the FileStream connection

this code use but i have given error in create external function..
--Error: Method has no implementation

static extern SafeFileHandle CreateFile(string lpFileName, FileAccess dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
Posted
Updated 28-Mar-14 21:42pm
v2

 
Share this answer
 
If you are trying to get that code to work in a ASP.NET scenario, then forget it, it won't work.
Sorry, that "could" work if the printer is attached to the server where your ASP.NET website is hosted. But that will not work if your intention is to allow your users to print to their client printers
If you want to send raw printer commands to the client printer from your ASP.NET website, then you'll need help from an external tool like this or this as there's no way to do that by using just ASP.NET framework.
 
Share this answer
 
Does the API you are calling contain this method?
Maybe you are not referencing the undamaged dll correctly.
 
Share this answer
 
Comments
antish1 29-Mar-14 3:59am    
which using ddl?

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