Tag: Dynamics NAV UTF-8

Text encoding in NAV 2009 R2 Classic Client – Part 2

As I already explained in this blog post you can import text files with encoding in Dynamics NAV 2009 R2 Classic Client and old versions.

Today, I will use the same trick to export a text file with encoding (UTF-8 in the example below).

To illustrate this, let’s export all items in a text file from a Russian database. I’ll use three possible solutions:

1- Via dataport:

Dataport-Export Item.jpg

2- Via codeunit using variable of type File:

Codeunit File-Export Item.jpg

3- Via codeunit using variable of type Automation (Stream):

Codeunit Stream-Export Item.jpg

Now, let’s see the results:

Result.jpg

We quickly notice that export via dataport or via File variable does not do the job as Russian characters are not exported correctly whereas export via Stream does the job perfectly.

As always, I let you download the objects and files I used in this blog post.

This blog is available also on Microsoft Dynamics NAV Community

Text encoding in NAV 2009 R2 Classic Client – Part 1

P.S: If you’re still using Microsoft Dynamics NAV 2009 R2 Classic Client or a previous version, then you may want to continue reading this blog post.

We all know that Microsoft Dynamics NAV 2009 R2 Classis Client supports ANSI only (code page 1252 or depends on your windows localization).

In order to import/export encoded files we usually use some workarounds. In fact, when you google (bing) you will find two main answers:

  • Ansi-Ascii converter: but you need to add new characters in the codeunit as they come up,
  • Use some third party tools: but this will create dependency and it will cause a headache to maintain your NAV platform.

The solution I personally prefer is to use “Microsoft ActiveX Data Objects 2.8 Library” automation. In fact, this Dll is available on every windows machine and it offers a an interesting object: Stream.

In order to use it, you need to:

  1. Know your text file encoding,
  2. Check that your OS supports the needed language,
  3. Use a simple code is your NAV:

CREATE(Stream);
Stream.Open;
Stream.Charset(_Charset);
Stream.LoadFromFile(_Path);
Line := Stream.ReadText(1024);
Stream.Close;

Let’s see how this works concretely. In the example below, I will use a Russian Windows Server (change English to Russian):

RegionAndLanguage

Then, I will use two Russian text files with different encoding: UTF-8 and IBM855 (OEM 855). Finally, I test all on a NAV 2009 R2 Russian Native Demo Database.

CronusRU

I’ll let you see the results:

Below some comments to understand the results:

CodeComment
FIL_IBM855Read a IBM855 encoded file with File variable
FIL_UTF8Read a UTF-8 encoded file with File variable
IBM_UTFRead a IBM855 encoded file with Stream automation and wrong Charset = UTF-8
STR_IBM855Read a IBM855 encoded file with Stream automation and correct Charset = IBM855
STR_UTF8Read a UTF-8 encoded file with Stream automation and correct Charset = UTF-8
UTF_IBMRead a UTF-8 encoded file with Stream automation and wrong Charset = IBM855

Finally, I’ll let you download the objects and the files I used in the examples here.

This blog is available also on Microsoft Dynamics NAV Community

© 2023 NAV NAB BLOG

Theme by Anders NorenUp ↑