Reading a comma separated values (csv) file in dynamics ax
Asked Answered
P

1

7

How do you open and parse a csv file in dynamics ax?

Purebred answered 8/12, 2010 at 18:31 Comment(0)
P
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;
}
Purebred answered 8/12, 2010 at 18:33 Comment(3)
one comment: while( commaTextIo.status == IO_Status::Ok ) of course. The code While(containFromRead) is reading until first empty line.Garrulity
@Garrulity would it be safe to do both?Flanders
it'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. FixedGarrulity

© 2022 - 2024 — McMap. All rights reserved.