Friday 9 January 2015

Simple way to import CSV File through X++

We have been importing excel file for such along time in ax. And i think this will be best example if you want to import the CSV file into AX through code.

void ImportTmpData()
{
    CommaIo          file;// = new commaIo(ItemFileName,'r');
    Container          con;
    Int                     counter;
    tmpImport        tmpImport;
    ;
   
   delete_from tmpImport;
    file = new CommaIo(fileName,'r');
    file.inRecordDelimiter("\r\n");
    file.inFieldDelimiter(",");

    if (file)
    {
        while(file.status() == IO_Status::OK)
        {
            con = file.read();
            counter++;
            if (con && counter >1)
            {
                tmpImport.field1                = conpeek(con,1);
                tmpImport.field2                = conpeek(con,2);
                 tmpImport.insert();
            }
        }
    }
}

No comments:

Post a Comment