Detecting completion (or failure) of Worksheet.PrintOut call in C#?

213 Views Asked by At

When printing to PDF using C# + Excel Interop what is the best practice for detecting when the file has successfully printed or if there was a problem?

I need to know so that my app can take the generated PDF file, rename it, move it to a shared network drive, email it, etc. (Perhaps I should build a dedicated SSIS app to handle that part... hmmm... then I have an excuse to learn SSIS/BIDS)

Simply polling the directory until File.Exists() or we reach some maxTries cap is not a very satisfying way to handle it.

I am using VS 2008 Pro, Excel 2003 (11.0 Object Library), and Adobe Acrobat 7.0 Pro. Running on WinXP SP3.

1

There are 1 best solutions below

0
On BEST ANSWER

I think the polling technique is fine. Its a common technique. I do agree that it'd be nice to have an AfterPrint(StatusCode) to match BeforePrint, but the Automation API doesn't provide for that, so poll away!!! It works for almost every process on linux, many windows services, and applications.