This is my code for printing an already generated PDF on website. The page allows the user to print that PDF file by selecting a printer from a list.
My code works fine when I run it from my local machine and the PDF is printed out from the selected printer, but when I deploy it to production web server (IIS 7) nothing happens when clicking on Print button and no exceptions or errors were raised.
I've checked that the file exists in the server as well as the executable C:\\Program Files\\Adobe\\Reader 10.0\\Reader\\AcroRd32.exe
, so I thought the issue could be related to permissions.
Checks performed in server:
All Users
,System
andIIS_IUSRS
users has R/W/E permissions on~/Content/Pdfs/
folderAll Users
,System
andIIS_IUSRS
users has R/W/E permissions onC:\Program Files\Adobe\Reader 10.0\Reader
folder.Identity of my Application Pool on IIS was changed from
ApplicationPoolIdentity
toLocalSystem
.private void Print(string file, string printerName) { string FilePath = Server.MapPath("~/Content/Pdfs/" + file); try { Process p = new Process(); p.StartInfo.FileName = @"C:/Program Files/Adobe/Reader 10.0/Reader/AcroRd32.exe"; p.StartInfo.Arguments = "/h /t \"" + FilePath + "\" \"" + printerName + "\""; p.StartInfo.RedirectStandardError = true; p.StartInfo.UseShellExecute = false; p.Start(); string stdout = p.StandardError.ReadToEnd(); p.WaitForExit(); const string fic = @"C:\Output.txt"; System.IO.StreamWriter sw = new System.IO.StreamWriter(fic); sw.WriteLine(stdout); sw.Close(); } catch (Exception e) { const string fic = @"C:\Error.txt"; System.IO.StreamWriter sw = new System.IO.StreamWriter(fic); sw.WriteLine(e.Message); sw.Close(); } }
What could be the problem?
UPDATE:
I've done more logging as suggested so i used Try...Catch
to log both output and exceptions (updated code). Once executed on server web Output.txt
file was created empty and Error.txt
file was not created.
No application errors/warnings were recorded on Event Viewer.
I opened a command prompt window on server and executing AcroRd32.exe /h /t "C:\inetpub\wwwroot\otweb\Content\Pdfs\orden20140627112547.pdf" "Bullzip Printer"
the file was successfully printed out.