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);
for i := 1 to StrLen(TextToWrite) do begin
if TextToWrite = 'æ' then
OutStream.Write(Byte1)
else if TextToWrite = 'ø' then
OutStream.Write(Byte2)
else if TextToWrite = 'å' then
OutStream.Write(Byte3)
else if TextToWrite = 'Æ' then
OutStream.Write(Byte4)
else if TextToWrite = 'Ø' then
OutStream.Write(Byte5)
else if TextToWrite = 'Å' then
OutStream.Write(Byte6)
else
OutStream.Write(TextToWrite);
end;
// Save the file
TempBlobLocal2.CreateInStream(IStream);
Hi SanderDk,
Thank you for your reply.
You are right, but when I save the file on my local computer, open it in Notepad and select "Save as", then I can see that it is "UTF-8".
The file must be imported into "EG Lønservice" and the letters æ, ø and å are not correct after the import.
If I manually make a text file with ANSI encoding using Notepad, then it works fine.
Best regards,
Morten
I would expect what you do to work correctly. If it does not, I'd write to a tempfile, then download that tempfile. This way you can set the TEXTENCODING on the outstream.
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);
for i := 1 to StrLen(TextToWrite) do begin
if TextToWrite = 'æ' then
OutStream.Write(Byte1)
else if TextToWrite = 'ø' then
OutStream.Write(Byte2)
else if TextToWrite = 'å' then
OutStream.Write(Byte3)
else if TextToWrite = 'Æ' then
OutStream.Write(Byte4)
else if TextToWrite = 'Ø' then
OutStream.Write(Byte5)
else if TextToWrite = 'Å' then
OutStream.Write(Byte6)
else
OutStream.Write(TextToWrite);
end;
// Save the file
TempBlobLocal2.CreateInStream(IStream);
Answers
According to MS Docs the Windows format is ANSI :
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-file-handling-and-text-encoding?wt.mc_id=DX-MVP-5003099#windows-format
Thank you for your reply.
You are right, but when I save the file on my local computer, open it in Notepad and select "Save as", then I can see that it is "UTF-8".
The file must be imported into "EG Lønservice" and the letters æ, ø and å are not correct after the import.
If I manually make a text file with ANSI encoding using Notepad, then it works fine.
Best regards,
Morten
I have the data in a Temp Blob and save it to a file like this:
TempBlob.CreateInStream(IStream, TEXTENCODING::Windows);
//TempBlob.CreateInStream(IStream, TEXTENCODING::UTF8);
//TempBlob.CreateInStream(IStream, TEXTENCODING::MSDos);
Filename := 'Test.txt';
DownloadFromStream(IStream, '', '', '', Filename);
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 = 'æ' then
OutStream.Write(Byte1)
else if TextToWrite = 'ø' then
OutStream.Write(Byte2)
else if TextToWrite = 'å' then
OutStream.Write(Byte3)
else if TextToWrite = 'Æ' then
OutStream.Write(Byte4)
else if TextToWrite = 'Ø' then
OutStream.Write(Byte5)
else if TextToWrite = 'Å' then
OutStream.Write(Byte6)
else
OutStream.Write(TextToWrite);
end;
// Save the file
TempBlobLocal2.CreateInStream(IStream);
DownloadFromStream(IStream, '', '', '', FileName);
end;