Code to create table data in CSV File in axapta 2012



CommaTextIo file;
container line;
CustTable custTable;
#define.filename(@'C:\Test\TestFile.csv')
#File
file = new CommaTextIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
while select AccountNum, Name from custTable
{
line = [
custTable.Name ,
custTable.Name];
file.writeExp(line);
}
info(strFmt("File %1 created in specified folder.", #filename));
}