2009-06-20 181 views
0

如何從C#.NET應用程序啓動文檔的打印? Word文檔已經存在於硬盤中。我只是希望在點擊按鈕事件後開始打印該Word文檔。如何從C#打印Word文檔?

+3

請更多信息,您是否正在生成文檔並且希望打印它?或者說,您的程序知道計算機上的Word文檔,並且您希望打印該文件? – 2009-06-20 15:26:32

回答

8
ProcessStartInfo psi = new ProcessStartInfo(wordFilename) 
{ 
    UseShellExecute = true, 
    Verb = "print", 
    RedirectStandardOutput = false, 
    CreateNoWindow = true 
}; 

using (Process p = new Process {StartInfo = psi}) 
{ 
    p.Start(); 
    p.WaitForExit(); 
} 
+1

您需要添加`p.WaitForExit()`(我認爲),但否則這是正確的方法。 – Noldorin 2009-06-20 15:43:35

2

要做到這種事情,您需要了解有關System.Diagnostics.Process,MSDN頁面顯示如何以pridnt Word文檔爲例。簡短版本:

System.Diagnostics.Process printProcess = new System.Diagnostics.Process(); 
printProcess.StartInfo.FileName = @"X:\test\print this.doc"; 
printProcess.StartInfo.Verb = "Print"; 
printProcess.StartInfo.CreateNoWindow = true; 
printProcess.Start();