Opening UTF-8 file result in strange chars

L

Lasse Edsvik

Hello

I have a slight problem, I'm trying to open a textfile that has been saved
as UTF-8. But when I run it it displays strange chars eventhough i've
specified that it should read the file as UTF-8 using the OpenTextFile
method of the filesystemobject. I need to open the file, then insert data to
a database, nothing will get printed out on screen so its not a html-charset
problem.

How do I fix this?

TIA
/Lasse
 
E

Evertjan.

Lasse Edsvik wrote on 03 sep 2007 in
microsoft.public.inetserver.asp.general:
I have a slight problem,

Why slight, Lasse?
I'm trying to open a textfile that has been
saved as UTF-8. But when I run it it displays strange chars eventhough
i've specified that it should read the file as UTF-8 using the
OpenTextFile method of the filesystemobject. I need to open the file,
then insert data to a database, nothing will get printed out on screen
so its not a html-charset problem.

How do I fix this?

What do you mean by "open a textfile" in ASP?

Show us your code [ONLY the relevant workingpart please]

What do you mean by "run it" after you open it?
Can you "run" a text file, or do you mean an ASP or HTML file?
 
L

Lasse Edsvik

Evertjan,

as a tested with:

(file is saved as UTF-8 )

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(Server.MapPath("/files/temp/test.csv"), 1 , -1)
Response.Write(f.ReadAll)
f.Close

Set f=Nothing
Set fs=Nothing
%>


Resulted in:

Firstname Surname Email
Ã¥Ã"ööööÃ- Ã-ööÃ-ä [email protected]


the file contains:

Firstname Surname Email
åÄööööÖ ÖööÖä [email protected]







Evertjan. said:
Lasse Edsvik wrote on 03 sep 2007 in
microsoft.public.inetserver.asp.general:
I have a slight problem,

Why slight, Lasse?
I'm trying to open a textfile that has been
saved as UTF-8. But when I run it it displays strange chars eventhough
i've specified that it should read the file as UTF-8 using the
OpenTextFile method of the filesystemobject. I need to open the file,
then insert data to a database, nothing will get printed out on screen
so its not a html-charset problem.

How do I fix this?

What do you mean by "open a textfile" in ASP?

Show us your code [ONLY the relevant workingpart please]

What do you mean by "run it" after you open it?
Can you "run" a text file, or do you mean an ASP or HTML file?
 
M

Martin Honnen

Lasse said:
as a tested with:

(file is saved as UTF-8 )

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

FileSystemObject does not support UTF-8, its Unicode support means
UTF-16 I think.
You might need to use ADODB.Stream to read in the UTF-8 encoded file.
 
E

Evertjan.

Lasse Edsvik wrote on 03 sep 2007 in
microsoft.public.inetserver.asp.general:
Evertjan,
What do you mean by "open a textfile" in ASP?

Show us your code [ONLY the relevant workingpart please]

[please do not toppost on usenet and do not quote signatures]
Evertjan,

as a tested with:

(file is saved as UTF-8 )

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Read this:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr06/hey04
19.mspx


??
 
L

Lasse Edsvik

That's exactly the code I'm using...


Evertjan. said:
Lasse Edsvik wrote on 03 sep 2007 in
microsoft.public.inetserver.asp.general:
Evertjan,
What do you mean by "open a textfile" in ASP?

Show us your code [ONLY the relevant workingpart please]

[please do not toppost on usenet and do not quote signatures]
Evertjan,

as a tested with:

(file is saved as UTF-8 )

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Read this:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr06/hey04
19.mspx


??
 
A

Anthony Jones

Lasse Edsvik said:
That's exactly the code I'm using...


As Martin has pointed out UTF-8 is not supported by FileSystemObject. Here
is one way to do it with ADODB:-

Dim oStream : oStream = Server.CreateObject("ADODB.Stream")

oStream.Open
oStream.LoadFromFile Server.MapPath("/files/temp/test.csv")
oStream.CharSet = "UTF-8"

Response.Write oStream.ReadText

What is the client going to do with this response? Load into Excel?

If there is a good reason for the CSV to be in UTF-8 encoding then the
response code page also needs to be UTF-8. That being the case it may be
better to send it as binary like this:-

<%

Response.ContentType = "text/csv"
Response.CharSet = "UTF-8"

Dim oStream : oStream = Server.CreateObject("ADODB.Stream")

oStream.Type = 1 'Binary
oStream.Open
oStream.LoadFromFile Server.MapPath("/files/temp/test.csv")

Response.BinaryWrite oStream.Read

%>

This avoids converting UTF-8 to Unicode only to have the response convert it
back to UTF-8 again.

How big is the actual file likely to be?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top