How do you open and parse a csv file in dynamics ax?
Asked
Active
Viewed 1.6k times
1 Answers
12
static void TestCommaTextIO(Args _args)
{
#File
CommaTextIo commaTextIo;
FileIOPermission permission;
container containFromRead;
int x;
int cols;
;
permission = new FileIOPermission('c:\\junk\\mycsv.csv',#io_read);
permission.assert();
commaTextIo = new CommaTextIO('c:\\junk\\mycsv.csv','R');
containFromRead = commaTextIo.read();
While(containFromRead)
{
cols = conLen(containFromRead);
for(x=1;x<=cols;x++)
{
print conpeek(containFromRead,x);
}
containFromRead = commaTextIo.read();
}
pause;
commaTextIo = null;
}

James Moore
- 2,501
- 6
- 26
- 29
-
2one comment: `while( commaTextIo.status == IO_Status::Ok )` of course. The code `While(containFromRead)` is reading `until first empty line`. – mazzy Apr 20 '18 at 13:26
-
@mazzy would it be safe to do both? – Devon Apr 28 '21 at 16:55
-
1it's good question. i think `While( commaTextIo.status == IO_Status::Ok )` is safe anyway. I think `While(containFromRead)` is not safe if csv contains empty line as regular data. Fixed – mazzy Apr 28 '21 at 18:09