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

SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...