Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PrintToPrinter - has it worked ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm making use of the call to 'PrintToPrinter()' method as part of a simple C# application. Ideally I want to know whether or not the report has printed OK.
I'd scoped my code as follows :
internal static bool DonePrinting()
{
bool okPrinted;
okPrinted = false;
// create report code ..
try
{
// Set report up and log on information for tables
crystalRpt.PrintOptions.PrinterName = "Printer1";
crystalRpt.PrintToPrinter(1, false, 0, 0);
// printed OK
okPrinted = true;
}
catch
{
okPrinted = false;
}
// clear up report work stuff
return okPrinted;
}

I had assumed that had there been a problem with the 'PrintToPrinter()' method the 'catch' element of my method would have come into play and the method would have returned 'false' to the calling code to indicate that there had been a problem with the report (Printer not found for instance).
However this does not appear to be the case - albeit that the printer is not found the method still returns a 'true' value.

Does anyone know how I can establish if the 'PrintToPrinter()' method has actually done the work its supposed to have done ?

Thanks in advance
Steve
 
what exactly are you trying to catch? looks like nothing.. throwing nothing, catching nothing? Might try a finally block that'll catch all the other garbage that goes through your catch block there, and see what that returns ? The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
I've used it successfully but I've never changed the printer, always used the default.
 
I need to establish whether the 'PrintToPrinter()' method has worked or not.
In the case(s) when it fails it usually throws a nasty error / warning indicating that the printer isn't available or the likes.
I need to trap for this - if the 'PrintToPrinter()' fails for some reason.
Can this be done ?
If so, how ?
Thanks again.
Steve
 
Ohhhh... I didn't read closely enough. I thought you were saying its never worked for you.

catch (Exception e)
{
...
}



Try that...put in your own code or message about the printer. Make it so that it prints to a printer that doesn't exist and see if it goes to the code in your catch block instead of giving you the error you're seeing now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top