Forum Discussion

FabriceB's avatar
FabriceB
Occasional Contributor
8 years ago
Solved

Nead to write utf8 Without BOM

Hi,   I need to read / Write into a textfile on utf-8 but without bom. Actually, if a use Writetotextfile with textencodingType 22 or aqfile.ctUTF8, my file have a BOM... when my application read t...
  • HKosova's avatar
    8 years ago

    Hi Fabrice,

     

    Both aqFile* and Scripting.FileSystemObject write UTF-8 files with BOM.

     

    To write a file without BOM, you can use this workaround that involves two ADO Stream objects:

    http://stackoverflow.com/questions/31435662/vba-save-a-file-with-utf-8-without-bom/31436631#31436631

    The example is in VBScript, but the code can be ported to other languages.

     

    Another way is to use the .NET method System.IO.File.WriteAllText(), which by default uses UTF-8 encoding without BOM. You will need to add the System.IO assembly to project properties > CLR Bridge.

    dotNET.System_IO.File.WriteAllText("C:\\no_bom.txt", "привет");