Skip to main content

Posts

Showing posts with the label text

How to read a CSV , txt file in AX 2009

1. First of all, make sure that the file is accessible and has sufficient permissions to read the file. 2. Now follow the below code which reads the file, reads all the lines in the file and inserts into the table. #File CommaIo aSCIIFile; Container recordsCon; FileIoPermission               perm; StudentTable                    studentTable; #define.ExampleFile(@"c:\test.txt") ; perm = new FileIoPermission(#ExampleFile, #io_read ); if (perm == null) { return; } // Grants permission to execute the CommaIo.new method. // CommaIo.new runs under code access security. perm.assert(); // BP deviation documented. aSCIIFile = new CommaIo( #ExampleFile ,#io_read); ttsbegin; while (aSCIIFile.status()== IO_Status::Ok) //Reading the ASCII file if records are there ...

How to read data from text (.txt) file with Ascii

It returns a container with the data in each line in the text file. That could be useful if you are reading a CSV file. In the following example I convert the container into text string and print it as an info message, line after line: void method1() { AsciiIo readFile; str line; container fileRecord; ; readFile = new AsciiIo("C:\\test.txt" , 'R'); readFile.inFieldDelimiter("1234567890abcdefghijklmnop"); fileRecord = readFile.read(); while (fileRecord) { line = con2str(fileRecord); info(line); fileRecord = readFile.read(); } } This is content of the text file: And that is the output generated with the code sample above: