AX2012将txt文件打印到打印机

时间:2016-12-01 08:31:32

标签: printing process axapta dynamics-ax-2012-r3

将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()收到错误消息:指定的文件未分配给应用程序。

我还在AOS上检查了扩展名.txt的分配。该方法在Server上运行。

我按照以下例子进行了处理:

How to print any file in Dynamics AX

Performing File IO with the TextIo Class [AX 2012]

1 个答案:

答案 0 :(得分:0)

好的,我欺骗了自己,

我已经通过AOS上的个人登录检查了文件分配。这里的分配是正确的,但源是由AOS服务用户执行的。未为AOS服务用户设置分配。可能是通过安装第三方软件。根据.txt到记事本的分配,它会按照需要运行。

感谢所有考虑过的人

相关问题