Warm tip: This article is reproduced from stackoverflow.com, please click
axapta x++

Save text file with code page UTF-8 in Axapta 3.0

发布于 2020-04-20 11:24:26

How do I make a text file with code page UTF-8 in Axapta 3.0?

I cannot use

myFile = new CommaIo(myFileName, 'W', 65001);

as we can in newer versions of Axapta. In Axapta 3.0 new CommaIo only have the first two parameters.

Questioner
Morten
Viewed
32
Alex Kwitny 2020-02-06 00:50

I've not worked in 3.0, but I have a few ideas for you that might send you the right way.

1) Do you have CommaTextIo or TextIo? Those are the objects where you can specify a code page.

2) Look in the AOT and see if you have a macro called #File, and inside if you have #utf8Format(65001), use the X-Ref (or Ctrl+F) to find other places in the system that use it. Then you can see how they might accomplish UTF-8

3) See if you can combine CommaIo with some .NET code, or just manually generated a CSV. Perhaps generate your CSV and write it, then read it and re-write it using a method like below (from MetadataXMLGenerator job):

void write(str _directory, str _name, str _text)
{
    str path;
    ;

    _text = System.Text.RegularExpressions.Regex::Replace(_text, '\n', '\r\n');
    if (!System.IO.Directory::Exists(_directory))
    {
        System.IO.Directory::CreateDirectory(_directory);
    }
    path = System.IO.Path::Combine(_directory, _name);
    System.IO.File::WriteAllText(path, _text, System.Text.Encoding::get_UTF8());
}