Moving a CSV File from one folder to another after import


I am using the below written code for moving the file into another folder after import ,This method is runnig successfully on my client machine but when i deployed it on another server it is throwing the error from below bold and highlighted line

Please Help if any idea…

server static void moveFile(str fileName, str newFileName)



Set permissionSet;

System.Exception netExcepn;


permissionSet = new Set(Types::Class);

permissionSet.add(new FileIOPermission(fileName,#io_write));

permissionSet.add(new InteropPermission(InteropKind::ClrInterop));





catch (Exception::CLRError)


info(“Caught ‘Exception::CLRError’.”);

netExcepn = CLRInterop::getLastException();





Have you seen a file moving function from WinApi library in AX? There is a function WinApi::moveFile(FromFile, ToFile). And there is an interesting keyword that is hardcoded for this method: CLIENT static int moveFile(FromFile, ToFile). You on the other hand have written your method where you explicitly want to work with SERVER side (you have a keyword SERVER up there).

Therefore my question is - did you use a generic path to save the file, i.e., something like C:\temp\myFile.csv ? If so then in this case the method would look for (and save) the file from the server perspective, which is in this case server’s C:\temp\ folder… which you might have no access to or such path may not even exist on that server… or otherwise it might happen that the AOS user might have no access to that path.

By the way, you have a try-catch construction there, so what is the actual exception message?


Hi Janis ,

WinApi::moveFile(), solved my problem , thanks for suggesting the solution, but previously when i was using it similarly it wont work thats why i used System.Io.File::moveFile,

One more thing if you could clear is that why,file::move() is working on one AOS but not on other and WinApi works at both the servers.

I think the answer is already in my previous post. The keyword to the problem (and solution) is “CLIENT”, WinApi::moveFile() runs on CLIENT side. When you are working with files in client-server architecture, you always have to think about from which perspective you are looking from at the particular moment. In both cases you were running the file move code from the SERVER side, so it could have happened that one system the AOS could get an access to the particular file path, but the other AOS couldn’t. get the access. It could also have happened that you passed a file path that existed on your local PC where AX client was run, but it didn’t exist on server machine…

Your code would have worked as well if only you would have used a keyword CLIENT instead of SERVER.