3
votes

I am developing a .Net application (C#) that views a report (.rdlc) and print it.

In case of successful printing I should update some status in the database.

But the problem I can't find a way to know that the printing is successful.

For reportviewer I have two events:

  • Print Event: It fires when user clicks on print button of reportViewer.

  • PrintingBegin Event:It fires when user clicks OK inside print dialogue - but in case of printer is offline or out of paper...etc, no indication is given and the application won't be able to know.

Is there a way to ensure that the printing process is successful?

Thanks

1
i'm going to redirect you to the following post, it contains information on how to read printer statusses etc... stackoverflow.com/questions/1622903/… - Schuere
I am not familiar with printer operations, but with a wild guess, If you are giving the print command, you can surround that code with a try-catch and check if any exception is thrown. - Tolga Evcimen
@Schuere even if he knows printer is OK before printing...it doesn't mean that printing won't fail (out of enough paper, any error, printer disconnected). Moreover he won't know which printer user will select (and with which parameters he'll print). - Adriano Repetti
@TolgaEvcimen Actually I generate a report in the report viewer and the viewer contains Print button that call windows printing dialogue without my intervention - AbdelRahman Shabana
I see, I'm sorry for not having any more useful ideas. - Tolga Evcimen

1 Answers

2
votes

It's not so immediate (and you have to handle it in different ways according to how print has been started) but you can do it.

If users click Print button then ReportViewer's OnPrint method will serve request. Any exception will be handled by (unfortunately internal) UpdateUiStatus method. That method (among other things) will raise ReportError event with exception informations. Just add a proper handler for that event and you'll know if print failed. Please note that you won't be notified if printing finished without errors.

Problem with this solution is that you have to understand if it's an event that comes from printer or not (so you have to deal with exception details).

Another way is to hide default print button exposed by ReportViewer control, if you invoke Print method directly then you can catch all exceptions and you'll know when printing started and if it worked or not.