I'm working on a demo application that prints a selected MS Word document to a printer.
I need to establish whether this was successful or not.
The code is as follows :
private void button1_Click(object sender, System.EventArgs e)
{
try
{
System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.FileName = @"C:\TEST3.doc";
p.StartInfo.UseShellExecute = true;
p.StartInfo.Verb = "print";
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
int i = p.ExitCode;
p.Dispose();
if (i == 0)
{
MessageBox.Show("Printed OK"
}
else
{
MessageBox.Show("DID NOT PRINT OK"
}
}
catch (Exception ex)
{
MessageBox.Show("Unable to print report" + "\n\n" + ex.ToString());
}
}
This works OK apart from when I unhook from the network and my report fails to be printed (no printer to print to).
It still returns an ExitCode of 0 (for successful).
How can I understand as to whether or not the report has actually been sent to the printer and not returned an error (i.e. it's not there) ?
Any help would be appreciated.
Thanks in advance
Steve
I need to establish whether this was successful or not.
The code is as follows :
private void button1_Click(object sender, System.EventArgs e)
{
try
{
System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.FileName = @"C:\TEST3.doc";
p.StartInfo.UseShellExecute = true;
p.StartInfo.Verb = "print";
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
int i = p.ExitCode;
p.Dispose();
if (i == 0)
{
MessageBox.Show("Printed OK"
}
else
{
MessageBox.Show("DID NOT PRINT OK"
}
}
catch (Exception ex)
{
MessageBox.Show("Unable to print report" + "\n\n" + ex.ToString());
}
}
This works OK apart from when I unhook from the network and my report fails to be printed (no printer to print to).
It still returns an ExitCode of 0 (for successful).
How can I understand as to whether or not the report has actually been sent to the printer and not returned an error (i.e. it's not there) ?
Any help would be appreciated.
Thanks in advance
Steve