Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

How to get encoding value in stream

(1) ShareShare
ReportReport
Posted on by 171
Hi Team
Using below link i have generated the .txt file.
 
Below code will store the stream value.
stream = io.getStream();
Below code will store the encoding value.
 
System.Text.Encoding encoding = System.Text.Encoding::get_UTF8()
Now from here i am calling BankStatementImportUtils class for generate the URL.
// For create the URLBankStatementImportUtils::sendFileToTempStore 
sendFileToTempStore method is passing only stream value and file name, i have to pass encoding value also.
 
Please let me know how to pass encoding value.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    How to get encoding value in stream in D365FO
    Now I'm not sure about the situation. I explained in another thread that Notepad++ simply tries to guess the encoding if the file doesn't contain any identification of encoding, such as Unicode BOM. But you choose the right encoding manually and check the file contents. And it's marked as the verified answer there.

    With this knowledge, do you see any problem with what your code generates?
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    How to get encoding value in stream in D365FO
    Sorry, my mistake.
     
    I need Shift-JIS encoding(932)
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    How to get encoding value in stream in D365FO
    No, it's not. You should have try to compile your code and you would have the answer immediately, without having to write down such a question and waiting for my reply. It won't even compile.
     
    As I said, it needs to be "a code page identifier, not an Encoding object", such as 65001. GetEncoding() is called inside constructForWrite().
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    How to get encoding value in stream in D365FO
    Hi Martin
    Is below code correct?
    io = TextStreamIo::constructForWrite(Encoding::GetEncoding(65001));
     
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    How to get encoding value in stream in D365FO
    sendFileToTempStore() doesn't accepting any Encoding object, therefore passing it there is impossible. You'll need to design a different solution.
     
    Why do you want to do such a thing?
     
    If your goal is generating text with a particular encoding, it's too late - the content was already generated and stored in the stream. You can set encoding (as a code page identifier, not an Encoding object) as a parameter of TextStreamIo::constructForWrite(). The method creates an Encoding object from the code page ID (by calling Encoding::GetEncoding()). The default value is 1200 (UTF-16LE); UTF-8 is 65001.

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans