Hi All,
This post will help the new AX developers who want to write the X++ code to read a *.CSV file. The below job reads files from a folder one by one.
static void importCSVFile(Args _args)
{
ASCIIIO file;
Container fileRead;
str line;
System.Array fileArray;
container fileCon;
int i, j;
FilenameOpen fileName;
;
fileArray = System.IO.Directory::GetFiles(invoiceFilePath,"*.csv");
for( i=0; i < ClrInterop::getAnyTypeForObject(fileArray.get_Length()); i++ )
{
fileCon = conins(fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject(fileList.GetValue(i)));
}
for(j=1 ; j<= conlen(fileCon) ; j++)
{
fileName = conPeek(fileCon, j);
file = new ASCIIIO(fileName, "R");
file.inRecordDelimiter('\n');
file.inFieldDelimiter(",");
fileRead = file.read();
while (file.status() == IO_STATUS::Ok)
{
fileRead = file.read();
line = conpeek(fileRead, 1);
if (line != "0")
{
info (conPeek(fileRead, 1));//Column 1
info (conPeek(fileRead, 2));//Column 2
info (conPeek(fileRead, 3));//Column 3
}
}
}
}
Regards,
K. Arunsubramaniam
This post will help the new AX developers who want to write the X++ code to read a *.CSV file. The below job reads files from a folder one by one.
static void importCSVFile(Args _args)
{
ASCIIIO file;
Container fileRead;
str line;
System.Array fileArray;
container fileCon;
int i, j;
FilenameOpen fileName;
;
fileArray = System.IO.Directory::GetFiles(invoiceFilePath,"*.csv");
for( i=0; i < ClrInterop::getAnyTypeForObject(fileArray.get_Length()); i++ )
{
fileCon = conins(fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject(fileList.GetValue(i)));
}
for(j=1 ; j<= conlen(fileCon) ; j++)
{
fileName = conPeek(fileCon, j);
file = new ASCIIIO(fileName, "R");
file.inRecordDelimiter('\n');
file.inFieldDelimiter(",");
fileRead = file.read();
while (file.status() == IO_STATUS::Ok)
{
fileRead = file.read();
line = conpeek(fileRead, 1);
if (line != "0")
{
info (conPeek(fileRead, 1));//Column 1
info (conPeek(fileRead, 2));//Column 2
info (conPeek(fileRead, 3));//Column 3
}
}
}
}
Regards,
K. Arunsubramaniam
Informative blog.
ReplyDeleteMicrosoft Azure Online Training
ReplyDeleteThank you for sharing wonderful information with us to get some idea about that content.Thank a lot for this post that was very interesting. Keep posting like those amazing posts, this is really awesome :) It is very useful.Thanks for sharing.
oracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
hadoop training in chennai
hadoop training in bangalore