Опитвам се да преместя файл, нищо умно.
Проблемът, който имам, е обяснен в блога на AX WONDERS.
Причината за това е, че когато се използва AX клас, който се изпълнява на сървъра, изключението никога не се връща към клиента и следователно не може да бъде обработено правилно.... операцията няма да попадне в изключението Exception::CRLError
Ако изходният файл се отвори от MSWord, например, се хвърля изключение в метода fileLocked, което е едновременно вбесяващо, но и забавно.
Всякакви предложения са добре дошли!
Малко код:
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::Delete(newFileName);
. Не забравяйте да хванетеCLRError
. - person Jan B. Kjeldsen   schedule 04.08.2013