Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top