Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Thursday, August 13, 2015

Write a text file in AX

Hi,

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 = @"C\Desktop\Reports.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();}

Regards,

No comments:

Post a Comment

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...