I have currently-working code which sends raw data to a printer by writing a temporary file, then using File.Copy()
to send it to the printer. File.Copy()
supports both local ports, like LPT1
and shared printers like \FRONTCOUNTERLabelPrinter
.
However, now I'm trying to get it working with a printer that's directly on the network: 192.168.2.100
, and I can't figure out the format to use.
File.Copy(filename, @"LPT1", true); // Works, on the FRONTCOUNTER computer
File.Copy(filename, @"\FRONTCOUNTERLabelPrinter", true); // Works from any computer
File.Copy(filename, @"\192.168.2.100", true); // New printer, Does not work
I know it's possible to "Add a printer" from each computer, but I'm hoping to avoid that - the second line of code above works from any computer on the network automatically, with no configuration required. I also know it's possible to P/Invoke the windows print spooler, and if that's my only option I may take it, but that's much more code overhead than I'd like to have.
Ideally, someone will have either a way to make File.Copy()
work or a similar C# statement which will accept a network IP.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…