2016-12-01 121 views
0

將AX2012 R3中的文本文件打印到特定打印機時出現問題。 這裏是我的源:AX2012將txt文件打印到打印機

public void printToPrinter(str _text, str printerName) 
{ 
    #File 
    System.Diagnostics.ProcessStartInfo processInfo; 
    System.Diagnostics.Process   process; 
    System.Exception     interopException; 
    TextIo        textIo; 
    PrintPathTable      printPath = PrintPathTable::find(); 
    str         fileName, arguments; 
    FileIoPermission     perm; 

    try 
    { 
     // Get the path and name. 
     fileName = this.getGuid(); 
     fileName = strFmt(@'%1%2',printPath.PrintPath, fileName); 

     // Assert permission. 
     perm = new FileIoPermission(fileName,'RW'); 
     perm.assert(); 

     // Open file for writing. 
     textIo = new TextIo(fileName, #IO_WRITE);   
     textIo.write(_text); 
     // Close the file. 
     textIo = null; 

     arguments = '\"' + printerName + '\"'; 

     process = new System.Diagnostics.Process(); 
     processInfo = process.get_StartInfo(); 
     processInfo.set_Verb('printto'); 
     processInfo.set_UseShellExecute(true); 
     processInfo.set_Arguments(arguments); 
     processInfo.set_FileName(fileName); 
     processInfo.set_WindowStyle(System.Diagnostics.ProcessWindowStyle::Hidden); 
        process.set_StartInfo(processInfo); 
     process.Start();   

        // revert asserted permissions 
        CodeAccessPermission::revertAssert(); 
    } 
    catch(Exception::CLRError) 
    { 
        interopException = CLRInterop::getLastException(); 
        while (!CLRInterop::isNull(interopException.get_InnerException())) 
        { 
            interopException = interopException.get_InnerException(); 
        } 

        error(strFmt('Fehler Druck "%1", "%2"', fileName, CLRInterop::getAnyTypeForObject(interopException.get_Message()))); 
    }  
} 

我得到錯誤信息在process.Start()每次:指定的文件未分配給應用程序。

我也檢查了擴展名爲.txt的AOS上的任務。該方法在Server上運行。

我照着下面的例子進行:

How to print any file in Dynamics AX

Performing File IO with the TextIo Class [AX 2012]

回答

0

好吧,我騙自己,

我與我的個人登錄上檢查文件分配AOS。這裏的分配是正確的,但源代碼是由AOS服務用戶執行的。沒有爲AOS服務用戶設置分配。可能通過安裝第三方軟件。根據記事本的.txt分配,它按需運行。

感謝所有曾考慮過的人