AX 2012: Moving File to another Folder using System.IO.File X++

static void ArisMoveFileUsingSystemIOFile(Args _args)
{
#File
Set permissionSet;
Filename fPath;
Filename fName;
Filename fType;

Filename sourcePath = @’D:\SourceFolder\test.csv’;
FileName DestinationPath = @’D:\DestinationFolder\’;

#define.sourcePath(sourcePath);
#define.destinationPath(DestinationPath)

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

CodeAccessPermission::assertMultiple(permissionSet);

[fPath, fName, fType] = fileNameSplit(sourcePath);

System.IO.File::Move(sourcePath, strFmt(‘%1%2%3’, #destinationPath, fName, fType));

CodeAccessPermission::revertAssert();

Box::info(‘File\s moved successfully!’);
}

Leave Comment

Your email address will not be published. Required fields are marked *