In this blog post, I will show you how to read a line from a text file in AX 2012 using X++.
This can be useful for importing data, parsing logs, or processing configuration files.
Here is an example of how to do that:
static void ReadTextFromFile(Args _args)
{
Filename filename = @'C:\ReadFrom\AX2012.txt';
System.IO.StreamReader reader;
System.String line;
InteropPermission interopPermission;
Str text;
interopPermission = new InteropPermission(InteropKind::ClrInterop);
interopPermission.assert();
reader = new System.IO.StreamReader(filename,System.Text.Encoding::get_UTF8());
line = reader.ReadLine();
while (!System.String::IsNullOrEmpty(line))
{
text = line;
info(strfmt("%1", text));
line = reader.ReadLine();
}
reader.Close();
reader.Dispose();
}