Text File UTF-8 Encoding

EL_TORRESHDZEL_TORRESHDZ Member Posts: 3
Hi can you guy helpme I want to write a text file from navision i can write in the file but som characters as Á or é are not correct when I open the file in the note pad I think it is because of the encoding navision save it in ANSI i think is that. ](*,)

Comments

  • FDickschatFDickschat Member Posts: 380
    NAV uses internally and when writing files ASCII, not ANSI. You will need to convert the data to ANSI before writing the file. Search the forum for ASCII ANSI, you will find lots of tips.
    Frank Dickschat
    FD Consulting
  • EL_TORRESHDZEL_TORRESHDZ Member Posts: 3
    Thanks now i can write character like é and Á in the text file encode ANSI but I need write the text file from NAV in default encode UTF-8 not in ANSI
  • MalajloMalajlo Member Posts: 294
    This can be done using PowerShell.
    .tmp file is temporary ANSI file, ptFileName is a full path to file (ie. c:\temp\filename.txt)
    WHS	Automation	'Windows Script Host Object Model'.WshShell	
    
    IF ISCLEAR(WHS) THEN CREATE(WHS) ;
    pwrShell := '%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe' ;
    pwrShellCmd := STRSUBSTNO('"Get-Content %1.tmp | Out-File %1 -Encoding UTF8"',ptFileName) ;
    whsWait := TRUE ;
    i := WHS.Run(pwrShell + ' ' +pwrShellCmd,whsWait,whsWait) ;
    ERASE(ptFileName+'.tmp') ;
    
  • code_eatercode_eater Member Posts: 5
    Hi
    Just my 2 cents in this:

    In 2013 there was a new System-Property "Textencoding" introduced. Have a sample here:

    http://msdn.microsoft.com/en-us/library ... 1(v=nav.71).aspx

    Using this, I think you don't need ASCIItoANSI Conversion anymore while exporting data.

    Hope this helps.
    Thomas
  • KowaKowa Member Posts: 923
    I have written some PowerShell conversion functions which you can easily adapt to all existing codepages by selecting the source/target file encoding.
    http://www.msdynamics.de/viewtopic.php?f=17&t=25726
    Keep in mind that these conversion can only work properly if a special character is part of a specific codepage. You can convert any codepage to unicode but not vice versa if the file contains characters which can't be mapped.
    Don't import these converted files to NAV without converting them back to the OEM codepage, unless you can make use of the file encoding parameter that was introduced in NAV 2013 R2.
    Kai Kowalewski
  • Rikt-ItRikt-It Member Posts: 37
    Hi

    I have used

    http://blogs.msdn.com/b/nav/archive/201 ... -2013.aspx

    to export / import files with Swedish special signs åäö..

    Regards

    Christer
    Regards
    Christer in Stockholm, Sweden
Sign In or Register to comment.