Archived Forum Post

Index of archived forum posts


Charset.VerifyFile always returns 0

Feb 08 '17 at 08:59

I'm trying to check whether a file has been saved with UTF-8 encoding (with/without BOM/preamble) but in my tests .VerifyFile always returns 0.

ActiveX | v9.5.0.60

sFilePathLocal = "e:\temp\test.txt"

with Server.CreateObject("Chilkat_9_5_0.FileAccess")
   .WriteEntireTextFile sFilePathLocal, "abc-£-123", "utf-8", 1
end with

with Server.CreateObject("Chilkat_9_5_0.Charset")
response.write .VerifyFile("utf-8", sFilePathLocal)
end with

Accepted Answer

Doh - I was using .UnlockComponent with the wrong code. Thank you!


Check the Charset object's LastErrorText property after calling VerifyFile.

Also, examine the contents of the test.txt file using a good editor such as EmEditor (where you can view as binary/hex) or use a hex editor.

The text.txt file should contain this: EF BB BF 61 62 63 2D C2 A3 2D 31 32 33

The "EF BB BF" are the utf-8 BOM bytes. The £ is composed of the bytes C2 A3 in utf-8.