Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Shift_JIS encoding in Business Central SaaS version

Posted on by 83

Hi All,

 

In BC SaaS version, it is only possible to export a file with TextEncoding::Windows/UTF-8/ASCII.

But one our customer want to export file with specific encoding type (shift_jis) and which is possible in NAV and BC Onprem versions with help of .NET variables. Is there any workaround to achieve below source code in BC SaaS version?

 

//[DotNet Variable: FilestreamWriter , FileEncoding ]

TextFile.WRITEMODE(TRUE);

TextFile.TEXTMODE(TRUE);

TextFile.CREATE(FileName);

TextFile.CREATEOUTSTREAM(FileOutStream);

FilestreamWriter := FilestreamWriter.StreamWriter(FileOutStream,FileEncoding.GetEncoding('shift_jis'));

Thanks

  • Suggested answer
    Dharmender Profile Picture
    Dharmender 83 on at
    RE: Shift_JIS encoding in Business Central SaaS version

    Thanks all for your time and suggestions. Achieved final result with following code.

    //DotNetEncoding: Codeunit DotNet_Encoding;

    //DotNetStreamWriter: Codeunit DotNet_StreamWriter;

    //932 : codepage for shift-jis encode

    //Fine Code

    TempBlob.CreateOutStream(OutStr);

    DotNetEncoding.Encoding(932);                                                    

    DotNetStreamWriter.StreamWriter(OutStr, DotNetEncoding);

    DotNetStreamWriter.WriteLine(HeaderLineJPText);            

    DotNetStreamWriter.Flush();  

    //Bad code

    TempBlob.CreateOutStream(OutStr);

    DotNetEncoding.Encoding(932);                            

    DotNetStreamWriter.StreamWriter(OutStr, DotNetEncoding);

    OutStr.Write(HeaderLineJPText);                              

    OutStr.WriteText();    

  • Dharmender Profile Picture
    Dharmender 83 on at
    RE: Shift_JIS encoding in Business Central SaaS version

    Thank Bruvik for your suggestion.

    Tried encoding codeunit but still it not working. exported file showing ???

    //65001:codepage for utf-8, 932: codepage for shift_jis.

    Encoding.Convert(65001, 932, HeaderLineJPText);

  • Dharmender Profile Picture
    Dharmender 83 on at
    RE: Shift_JIS encoding in Business Central SaaS version

    Thanks ZHU for your suggestion.

    My basic requirement is to export data from BC SaaS with Shift-JIS encoding text file.

    Tried with the following code but Japanese characters showing ????? format.

    //65001:codepage for utf-8, 932: codepage for shift_jis.

    Encoding.Convert(65001, 932, HeaderLineJPText);

    -----------------------------------------------------------------------------

    12100077777777?)??????????                            02180005?????????????

    -----------------------------------------------------------------------------

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,664 Super User 2024 Season 2 on at
    RE: Shift_JIS encoding in Business Central SaaS version

    Hi, I think what Inge mentioned should be codeunit 1486 "Encoding". You can have a try.

    pastedimage1683507883482v1.png

    pastedimage1683507936231v2.png

    And, some info in MS Docs:

    File Handling and Text Encoding
    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-file-handling-and-text-encoding

    Hope this helps as well.

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: Shift_JIS encoding in Business Central SaaS version

    In BC Online there is an encoding codeunit avalible in the system app.T

    The codeunit 1406 called Encoding. Takes a text and a Destination codepage as parameter. Maybe you can use that function?

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans