1

Using ASP's file system object (FSO), I'm trying to read a txt file with OpenTextFile that contains French characters (e and a with accents for e.g). Those characters come out wrong.

I tried specifying the format to TristateTrue to open the file as Unicode but to no avail.

I've been reading about using the ADO Stream object instead but I hoped there would be a way with FSO. Does anyone have any ideas?

greener
  • 4,989
  • 13
  • 52
  • 93

1 Answers1

3

Most likely the file is saved in UTF-8 encoding. The FileSystemObject does not handle UTF-8.

Either have the file saved as Unicode or use the ADODB.Stream object. The ADODB.Stream has a LoadFromFile method and does support UTF-8.

 Dim s

 Dim stream : Set stream = CreateObject("ADODB.Stream")

 stream.CharSet = "UTF-8"
 stream.LoadFromFile Server.MapPath("yourfile.txt")

 s = stream.ReadAll

 stream.Close
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • It should be noted this will only work if the stream is opened first with `stream.Open`. Also, maybe something with the API has changed since this answer was written, but the I think the correct method is `stream.ReadText`. – Leslie Krause Dec 08 '22 at 02:47