web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to save an ANSI file from Business Central

(4) ShareShare
ReportReport
Posted on by 143
Hi experts,
 
This is regarding Business Central cloud.
 
When I make a file, I can set the encoding to Windows, UTF-8, UTF-16 and MSDOS.
 
Our customer need a file with ANSI encoding.
 
How do I do that?
 
Hope, you can help.
 
Morten
I have the same question (0)
  • Verified answer
    MS-07051042-0 Profile Picture
    143 on at
    How to save an ANSI file from Business Central
    Hi YUN ZHU and Khushby Rajvi,
     
    Thank you for your reply.
     
    Since Microsoft don't support making an ANSI encoded file (with our local, Danish, letters), I have made it myself (with a little help from my friend, Erik Hougaard on YouTube).
     
    This way it is working fine and our customer does not have to pay for the Azure functions.
     
    I saw how Erik Hougaard made an app that created a WAVE file and I used that to make the code below. I know it does not support all letters and signs, but this is what the customer is willing to pay for - and it is all they need.
     
    procedure SaveAnsiEncodedTextFileFromTempBlob(var TempBlobLocal: Codeunit "Temp Blob"; FileName: Text)
    var
        InStream, IStream : InStream;
        OutStream: OutStream;
        TempBlobLocal2: Codeunit "Temp Blob";
        TextToWrite: Text;
        i: Integer;
        Byte1, Byte2, Byte3, Byte4, Byte5, Byte6 : Byte;
    begin
        // Read text from TempBlob
        TempBlobLocal.CreateInStream(InStream, TextEncoding::UTF8);
        InStream.ReadText(TextToWrite);
     
        TempBlobLocal2.CreateOutStream(OutStream);
     
        Byte1 := 230; // æ
        Byte2 := 248; // ø
        Byte3 := 229; // Ã¥
        Byte4 := 198; // Æ
        Byte5 := 216; // Ø
        Byte6 := 197; // Ã…
     
        for i := 1 to StrLen(TextToWrite) do begin
            if TextToWrite[i] = 'æ' then
                OutStream.Write(Byte1)
            else if TextToWrite[i] = 'ø' then
                OutStream.Write(Byte2)
            else if TextToWrite[i] = 'Ã¥' then
                OutStream.Write(Byte3)
            else if TextToWrite[i] = 'Æ' then
                OutStream.Write(Byte4)
            else if TextToWrite[i] = 'Ø' then
                OutStream.Write(Byte5)
            else if TextToWrite[i] = 'Ã…' then
                OutStream.Write(Byte6)
            else
                OutStream.Write(TextToWrite[i]);
        end;
     
        // Save the file
        TempBlobLocal2.CreateInStream(IStream);
     
        DownloadFromStream(IStream, '', '', '', FileName);
    end;
     
  • Suggested answer
    YUN ZHU Profile Picture
    90,070 Super User 2025 Season 2 on at
    How to save an ANSI file from Business Central
    Hi, The following four types are standard. If you need others, you need to use external services such as Power Automate, Azure Function, etc.
     
    Hope this helps as well
    Thanks.
    ZHU
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    18,989 Super User 2025 Season 2 on at
  • MS-07051042-0 Profile Picture
    143 on at
    How to save an ANSI file from Business Central
    Hi KP,
     
    Thank you for your reply.
     
    I use the default instream functionality already. I have the values in a TempBlob and do this to make the file:
     
    TempBlob.CreateInStream(IStream, TEXTENCODING::UTF8);
    //TempBlob.CreateInStream(IStream, TEXTENCODING::Windows);
    //TempBlob.CreateInStream(IStream, TEXTENCODING::MSDos);
     
    Filename := 'Test.txt';
    DownloadFromStream(IStream, '', '', '', Filename);
     
    I have tried UTF8, Windows and MSDos and none of them make an ANSI-encoded file.
     
    How do I use Azure functions? I have never done that. I don't use "namespace" or "using" in AL.
     
    Best regards,
     
    Morten
  • Suggested answer
    KP - Solution Architect Technical Profile Picture
    652 on at
    How to save an ANSI file from Business Central
    Hi,
     
    You can use the default in-stream and outstream method for saving the ANSI file format Additionally Azure functions can be used
     
    Thanks,
    KP

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,689 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,631

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,212

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans