简体   繁体   English

AX2012将txt文件打印到打印机

[英]AX2012 Print txt file to printer

i have a problem when printing a text file from AX2012 R3 to a specific printer. 从AX2012 R3将文本文件打印到特定打印机时,我遇到问题。 Here is my source: 这是我的资料来源:

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())));
    }    
}

I get the error message every time in the process.Start() : The specified file is not assigned to an application. process.Start()每次都收到错误消息:指定的文件未分配给应用程序。

I also checked the assignment on the AOS for the extension .txt. 我还检查了扩展名.txt在AOS上的分配。 The method is run on Server. 该方法在服务器上运行。

I have proceeded according to the following examples: 我根据以下示例进行了操作:

How to print any file in Dynamics AX 如何在Dynamics AX中打印任何文件

Performing File IO with the TextIo Class [AX 2012] 使用TextIo类执行文件IO [AX 2012]

Ok, I've tricked myself, 好吧,我欺骗了自己,

I have checked the file assignments with my personal login on the AOS. 我已经通过AOS上的个人登录检查了文件分配。 Here the assignments were correct, but the source is executed with the AOS service user. 这里的分配是正确的,但是源是由AOS服务用户执行的。 The assignment was not set for the AOS service user. 未为AOS服务用户设置分配。 Probably by installing a third-party software.According to the assignment of the .txt to the notepad, it runs as desired. 可能是通过安装第三方软件。根据.txt在记事本中的分配,它可以按需运行。

Thanks to all who have considered 感谢所有考虑过的人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM