2014-07-21 71 views
1

看起來,當試圖在Windows 7 64位(SP1)盒子上使用System.Drawing.Printing.PrintDocument命名空間時,它很好用。但是,在Server 2008 R2 64位(SP1)框上嘗試相同的代碼,並且它只是掛在代碼中。沒有異常拋出,等...Windows Server 2008 R2 Standard的PrintDocument問題64位

這裏是我的代碼片段...

private bool PrintTIF(string sPrinter, string sFile) 
{ 
    try 
    { 
     //Open file for printing 
     WriteEvent(105, "Opening the file for printing using streamreader...", CustomLogTool.EventLogEntryTypeExtentions.Debug); 
     m_PrinterFile = new StreamReader(sFile); 

     //Set the document name 
     WriteEvent(105, "Set the document name.", CustomLogTool.EventLogEntryTypeExtentions.Debug); 
     m_Printer.DocumentName = Path.GetFileName(sFile); 

     //Print file 
     WriteEvent(105, "Sending the file to the printer...", CustomLogTool.EventLogEntryTypeExtentions.Debug); 
     m_Printer.Print(); 
     m_PrinterFilesPrinting.Add(new PrintInfo(sFile, null, sPrinter)); 

     //Close file 
     WriteEvent(105, "Closing the file and destorying the streamreader object.", CustomLogTool.EventLogEntryTypeExtentions.Debug); 
     m_PrinterFile.Close(); 

     //Success 
     return true; 
    } 
    catch (Exception ex) 
    { 
     try { m_PrinterFile.Close(); } 
     catch { } 
     WriteEvent(201, ex.Message, CustomLogTool.EventLogEntryTypeExtentions.Debug); 

     return false; 
    } 
} 

我得到記錄事件上升到「將文件發送到打印機...」。我什麼都得不到,我希望在異常中得到我的錯誤201消息。但我什麼也沒得到。就好像程序被掛起一樣。我猜這是由於已經從Win7(SP1)更改爲Server2008R2(SP1)的原因。有任何想法嗎?

+1

從不,*從不*,**從不**嘗試從服務打印。您看不到打印機驅動程序警報。 –

+0

我的應用程序的重點是從服務打印...爲什麼我不能將這些「打印機驅動程序警報」包裝到事件日誌條目中?你能否詳細說明「打印機驅動程序警報」?他們是什麼,我怎麼能看到他們或獲得他們的訪問等...任何... –

回答

0

解決方案: 我想清楚我的問題是什麼。這與我一直選錯打印機的事實有關!很浪費時間去做這麼簡單的事情,但它確實讓我走上了一條不同的方式來調試它。在我開始使用正確的打印機後,我發現我的下一個問題是一個不是實際TIFF文件的TIFF文件。它碰巧是一個0字節的測試文件,我忘了我在測試目錄中。

我的新的方法來調試這些服務的打印機問題: 找出發生了什麼事情是走出來的「服務領域」了一點的最好辦法。將它編譯爲調試構建並以這種方式可以將它作爲控制檯應用程序運行。將它構建爲版本構建需要您將其作爲服務運行,並且不會讓您手動運行它。當我將它構建爲一個Debug版本時,我將它從目錄中的服務器上運行,然後彈出一個Windows對話框......它問我想要將我的文件保存爲。不久之後,我發現它是默認的「Microsoft XPS Document Writer」打印機!

然後我去,改變了打印機的一個,我想(通過代碼)...

PrintDocument pd = new PrintDocument(); 
pc = new StandardPrintController(); 
pd.PrintController = pc; 
// Yadda Yadda Yadda... 
pd.PrinterSettings.PrinterName = "My Printer Name"; 

希望它可以幫助別人了,太節省了他們一定的時間!祝你好運!

相關問題