views:

394

answers:

1

How can I launch the print of a document from C# .NET application ? the word document already exists in the hard drive. I just wish to start printing that word document upon the button click event.

+5  A: 
 ProcessStartInfo psi = new ProcessStartInfo(wordFilename)
 {
    UseShellExecute = true,
    Verb = "print",
    RedirectStandardOutput = false,
    CreateNoWindow = true
 };

 using (Process p = new Process {StartInfo = psi})
 {
     p.Start();
     p.WaitForExit();
 }
Chris Doggett
You need to add `p.WaitForExit()` (I think), but otherwise this is the right way to do it.
Noldorin
@Noldorin: Thanks. That would've solved my problem with it closing the form before printing on this question: http://stackoverflow.com/questions/878878/webbrowser-control-wont-print-from-c
Chris Doggett
Ah, well I'm glad I've answered another question at least. :)
Noldorin