Ask a Question

Nead to write utf8 Without BOM

SOLVED
FabriceB
Occasional Contributor

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 this BOM... it BOOOOOM.

 

it is possible to read/write without this Bom ?

 

Thx

 

Fabrice

3 REPLIES 3
tristaanogre
Esteemed Contributor

Rather than using the aqFile.OpenTextFile, etc., you could instantiate the FileSystemObject yourself an use it's native functions (aqFile and aqFileSystem provide wrappers around those methods). 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
HKosova
SmartBear Alumni (Retired)

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", "привет");

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
FabriceB
Occasional Contributor

Hi all,

 

Thanks for your responses...

 

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

It works fine, thanks again

 

Fabrice

cancel
Showing results for 
Search instead for 
Did you mean: