Opening UTF-8 file result in strange chars

Opening UTF-8 file result in strange chars

am 03.09.2007 16:48:34 von 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

Re: Opening UTF-8 file result in strange chars

am 03.09.2007 16:52:58 von exjxw.hannivoort

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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Opening UTF-8 file result in strange chars

am 03.09.2007 17:10:00 von 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
Ã¥Ã"ööööÃ- Ã-ööÃ-ä labb01@labb.100procent.com


the file contains:

Firstname Surname Email
åÄööööÖ ÖööÖä labb01@labb.100procent.com







"Evertjan." wrote in message
news:Xns99A0ABBD13C87eejj99@194.109.133.242...
> 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?
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Re: Opening UTF-8 file result in strange chars

am 03.09.2007 17:17:30 von Martin Honnen

Lasse Edsvik wrote:

> 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.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Re: Opening UTF-8 file result in strange chars

am 03.09.2007 17:33:05 von exjxw.hannivoort

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/qand a/apr06/hey04
19.mspx


>> 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?

??


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Opening UTF-8 file result in strange chars

am 04.09.2007 09:47:17 von Lasse Edsvik

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


"Evertjan." wrote in message
news:Xns99A0B28A2C8FCeejj99@194.109.133.242...
> 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/qand a/apr06/hey04
> 19.mspx
>
>
> >> 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?
>
> ??
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Re: Opening UTF-8 file result in strange chars

am 04.09.2007 11:02:20 von Anthony Jones

"Lasse Edsvik" wrote in message
news:O96eKbs7HHA.5316@TK2MSFTNGP04.phx.gbl...
> 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?

--
Anthony Jones - MVP ASP/ASP.NET