簡體   English   中英

AX2012將txt文件打印到打印機

[英]AX2012 Print txt file to printer

從AX2012 R3將文本文件打印到特定打印機時,我遇到問題。 這是我的資料來源:

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上的分配。 該方法在服務器上運行。

我根據以下示例進行了操作:

如何在Dynamics AX中打印任何文件

使用TextIo類執行文件IO [AX 2012]

好吧,我欺騙了自己,

我已經通過AOS上的個人登錄檢查了文件分配。 這里的分配是正確的,但是源是由AOS服務用戶執行的。 未為AOS服務用戶設置分配。 可能是通過安裝第三方軟件。根據.txt在記事本中的分配,它可以按需運行。

感謝所有考慮過的人

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM