I have problem with printing *.prn file. This is code:
Process process1 = new Process();
process1.StartInfo.FileName = "copy";
process1.StartInfo.Arguments = string.Format(@" /b C:/test/test.prn \\127.0.0.1\{0}",
SelectPrinterForm.selectedLine);
process1.Start();
in SelectPrinterForm.selectedLine I have name of choosen printer. I’ve got error on Start() method with information cannot find file.
Edit (added stack trace):
w System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
w System.Diagnostics.Process.Start()
Questions:
Any suggestion why I’ve got this error?
Also why when I use “@” I still have "\\\\" instead of "\\" ?
Solution with help Hans Passant and his answer above
Process process1 = new Process();
string computerFullName = Program.GetFQDN();
process1.StartInfo.FileName = "cmd.exe";
process1.StartInfo.Arguments = string.Format(@" /c copy /B C:\test\test.prn \\{0}\{1}",
computerFullName,
SelectPrinterForm.selectedLine);
process1.Start();
“copy” is not an executable file in Windows, it is a command for the command interpreter, cmd.exe. The equivalent would be Filename = “cmd.exe”, Arguments = “/c copy ” + string.Format(…). You probably won’t be pleased with the command window or the lousy error reporting that produces, consider File.Copy() instead.
That’s a debugger artifact, it does not know whether or not you used @ in your code so errs on the safe side and displays the string as a regular C# string literal. Use the text visualizer to see the string as-is, click the spyglass icon.