Write a text file in AX


static server void WriteTextFile(Args _args){TextIo file;// Using the @ before the filename// enables us to use single path// delimiters. If you don’t use it// you will have to write the path like this:// “c:\temp\cars.txt”FileName filename = @”CDesktopReports.txt”; //Here give your location where to saveEmpTrainingTable empTrainingTable;container con;
FileIoPermission permission;#File;try{    // Create the permission classpermission = new FileIoPermission(filename, #io_write);// Add a request for permission before new TextIo()permission.assert();// Create the TextIo objectfile = new TextIo(filename, #io_write);if (!file)
throw Exception::Error;
// Specify the delimitersfile.outRecordDelimiter(#delimiterCRLF);file.outFieldDelimiter(“;”);// Loop through the data sourcewhile select empTrainingTable
{// Empty the containercon = connull();// Set the data into the containercon = conins(con, 1, empTrainingTable.DeptId);con = conins(con, 2, empTrainingTable.EmpTrainingId);con = conins(con, 3, empTrainingTable.Name);con = conins(con, 4, empTrainingTable.Phone);con = conins(con, 5, empTrainingTable.Date);// Write the container to the filefile.writeExp(con);}}catch(Exception::Error)
{error(“You do not have access to write the file to the selected folder”);}// Revert the access privilegesCodeAccessPermission::revertAssert();}

Leave a Reply

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