Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Shift_JIS encoding in Business Central SaaS version

(0) ShareShare
ReportReport
Posted on by 88

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 88 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 88 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 88 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 75,595 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 993 Super User 2024 Season 1 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?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans