移动文件,AX2012 [英] Move a file, AX2012

查看:158
本文介绍了移动文件,AX2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试移动文件,没有什么聪明的方法。

I'm trying to move a file, nothing clever.

AX WONDERS博客


这样做的原因是,当使用在服务器上运行的AX类时,异常永远不会返回到客户端,因此无法正确处理....该操作不会陷入异常: :CRLError异常

The reason for this is that when using an AX class that runs on the server, the exception never comes back to the client and therefore cannot be handled correctly.... the operation will not fall into the Exception::CRLError exception

例如,如果源文件由MSWord打开,则会在 fileLocked中引发异常。

If the source file is opened by MSWord, for example, an exception is thrown in the fileLocked method, which is both infuriating yet amusing.

任何建议都非常欢迎!

某些代码:

server static void moveFile(str fileName, str newFileName)
{
    #File
    Set                 permissionSet;
    ;

    permissionSet =  new Set(Types::Class);
    //permissionSet.add(new FileIOPermission(fileName,#io_write));
    permissionSet.add(new FileIOPermission('',#io_write));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));

    CodeAccessPermission::assertMultiple(permissionSet);

    if (isRunningOnServer()) 
    { 
        if (WinAPIServer::fileExists(newFileName))
            WinAPIServer::deleteFile(newFileName);
        WinAPIServer::copyFile(fileName, newFileName);
        if (!WinAPIServer::fileLocked(fileName))
            WinAPIServer::deleteFile(fileName);
    }
    else
    {
        if (WinApi::fileExists(newFileName))
            WinApi::deleteFile(newFileName);
        WinAPI::copyFile(fileName, newFileName);
        if (!WinAPI::fileLocked(fileName))
            WinAPI::deleteFile(fileName);
    }
    //System.IO.File::Move(fileName, newFileName);

    CodeAccessPermission::revertAssert();
}

错误注册表:

System.IO.IOException: The process cannot access the file 'M:\Interfaces\Prod\ImportacionClientes\Direcciones\XXXXXXAD_20130711_1136.TXT' because it is being used by another process.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

   at System.IO.File.OpenWrite(String path)

   at Dynamics.Ax.Application.WinAPIServer.fileLocked(String _fileName) in WinAPIServer.fileLocked.xpp:line 33

   at Dynamics.Ax.Application.EVE_UlaboxInterfaceClientes_IN.moveFile(String fileName, String newFileName) in EVE_UlaboxInterfaceClientes_IN.moveFile.xpp:line 19


推荐答案

我会去

 System.IO.File::Move(fileName, newFileName);

而不是变得聪明。
认为 newFileName 的先前存在是错误。

instead of being to clever. Consider the prior existence of the newFileName an error.

不要使用<$ c服务器或批处理上下文中的$ c> WinAPI 文件方法(已检查)。

同时使用 WinAPI WinAPIServer 太痛苦了,直接使用.Net方法。

Don't use the WinAPI file methods in a server or batch context (you checked that).
Using both WinAPI and WinAPIServer is just too painful, go straight for the .Net methods.

很有可能fileLocked 错误。

这篇关于移动文件,AX2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆