Bojensen Blogs

An alternative to the WinApi functions

 

The WinApi class holds some nice functions for file manipulation, like the

WinApi::fileExists
WinApi::copyFile
WinApi::deleteFile
WinApi::moveFile

I think every programmer has used one of those functions in Ax at one time or another, as they can be really helpful.

They have one big drawback though: They need to be executed on the client tier. Trying to use these functions in batch processing (so on the AOS), will result in errors.

Now you might wanna have a look at the WinAPIServer class. This class holds similar functions as the WinApi class, but these methods run on the server. This is a good alternative when you need to do some file manipulation in batch mode, but overall functionality is a bit limited here. Of course, you are free to extend the WinAPIServer class with your own, desired methods.

Or you can take a shortcut and use the CLRInterop way. Use the System.IO.File and System.IO.Directory namespace.

Examples:
System.IO.File::Copy
System.IO.File::Delete
System.IO.File::Exists
System.IO.File::Move
System.IO.Directory::Exists
System.IO.Directory::CreateDirectory

Assigning your CLR Interop permissions, and you’re good to go!

Comments are closed.