How to read Data from Text File

Today I will demonstrate you that how to read data from text file by using TextIO class in AX.

static void ReadTextFile(Args _args)
{
TextIo file;
FileName filename = @"c:\temp\cars.txt";
CarTable carTable;
container con;
FileIoPermission permission;
#File
;
try
{
permission = new FileIoPermission(filename, #io_read);
permission.assert();
file = new TextIo(filename, #io_read);
if (!file)
throw Exception::Error;
file.inRecordDelimiter(#delimiterCRLF);
file.inFieldDelimiter(";");
info("CarId - CarBrand - Mileage – Model - ModelYear");
con = file.read();
while (file.status() == IO_Status::Ok)
{
info(strfmt("%1 - %2 - %3 - %4 - %5",
conpeek(con,1),
conpeek(con,2),
conpeek(con,3),
conpeek(con,4),
conpeek(con,5)));
con = file.read();
}
}
catch(Exception::Error)
{
error("You do not have access to write the file to the selected folder");
}
CodeAccessPermission::revertAssert();
}

Comments