I have the below code in ASP.NET C# and it work fine in local system + production machine when i tested in debug mode. but it doesn't work when i uploading to IIS.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Server.MapPath(filePath);
startInfo.Verb = "print";
startInfo.Arguments = "Printer Name";
Process proc = new Process();
proc.StartInfo = startInfo;
proc.Start();
proc.WaitForExit(5000);
if (proc.HasExited == false)
{
proc.Kill();
}
Things i tried.
I tried all the above with no success. finally i tried below in my machine.config.
I replaced this
processModel autoConfig="true"
with this
processModel userName="SYSTEM" password="AutoGenerate"
and i am getting this message
"Before you can perform print-related tasks you need to install a printer"
i am using acrobat 7 and i can print the test page from printer itself and from acrobat software.
The issue may be that IIS runs under a different user that has less permissions than a typical User. See System.Diagnostics.Process.Start not work from an IIS
I fixed it on my server by changing the ProcessModel Identity to a user that has permissions. Probably a workaround and bad practice, but it worked. {Application Pool} -> Advanced Settings -> Identity -> Custom Account (Also toggle Load User Profile to true)
you can use Verb if acrobat is installed on you machine. and pass printer name as arguments
var fileName = @"c:\pdf\file.pdf";
var startInfo = new ProcessStartInfo(fileName);
string verbToUse = "PrintTo";
startInfo.Verb = verbToUse;
startInfo.Arguments = "PrinterName";
Process p = Process.Start(startInfo);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.