Move File from One Folder to Another Folder using X++

Hi Guys . I hope you are doing Good.

Today i’m going to share you that , how to move a File from One Folder to another folder using X++.

Here we can achieve this with the Help of WINAPI(Windows Application Programming Interface). Even though we can do Copy a file, delete a file, Create Directory, getting the file Size, etc. Refer more Details WINAPI

static void MoveFilesFromFoldertoAnotherFolder(Args _args)
 FilenameOpen fileNameOpen;
 DialogField dialogFileName;
 Dialog dialog;
 Filename filePath;
 Filename fileName;
 Filename fileType;
 FileName DestinationPath;
DestinationPath = @'C:\Users\saadullah\Desktop\Dest\'; // Define your Destination Path
 dialog = new Dialog("Move Files");
// AX 2009
 dialogFilename = dialog.addField(typeId(FileNameOpen));
// AX 2012
 // dialogFileName = dialog.addField(extendedTypeStr(FileNameOpen));
 dialog.filenameLookupTitle("Select File");
 dialog.caption("Move File");
filenameOpen = dialogFilename.value();
 [filePath, fileName, fileType] = fileNameSplit(fileNameOpen);
// MoveFile - The Original File won't be available once it's moved into destination path
WinAPI::moveFile(fileNameOpen, DestinationPath+FileName+FileType);
// CopyFile - The Original File will be available even if it's moved into destination path
 //WinAPI::copyFile(fileNameOpen, DestinationPath+FileName+FileType);
// DeleteFile - Delete the Selected File
 // If u need to Use this in Form Take look in AOT > Forms > Tutorial_Form_File

2 thoughts on “Move File from One Folder to Another Folder using X++

  1. Thank you this code is great, but do you know how to automatically get the AOT server to copy the file to the server? i know in C# its something like server.mappath();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s