473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Opening UTF-8 file result in strange chars

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
Sep 3 '07 #1
6 11856
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)
Sep 3 '07 #2
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
Ã¥Ã"ööööÃ- Ã-ööÃ-ä la****@labb.100procent.com
the file contains:

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



"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@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)

Sep 3 '07 #3
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/
Sep 3 '07 #4
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/scr...da/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)
Sep 3 '07 #5
That's exactly the code I'm using...
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@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/scr...da/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)

Sep 4 '07 #6
"Lasse Edsvik" <la***@nospam.comwrote in message
news:O9**************@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
Sep 4 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lawrence | last post by:
Someone on www.php.net suggested using a seems_utf8() method to test text for UTF-8 character encoding but didn't specify how to write such a method. Can anyone suggest a test that might work?...
4
by: zach | last post by:
Hi My problem is that on some sites when I click on a picture (for example) that is supposed to open in a new window it doesn't. The bottom left of my browser where it tells what is happening...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
4
by: Andrew J | last post by:
I have an intranet asp application that sends emails that contain a link to an intranet page. I have a case where one user is forced to login to the windows domain when he clicks on the link, even...
1
by: stevelooking41 | last post by:
Can someone explain why I don't seem unable to use document.write to produce a valid UTF-8 none breaking space sequence (Hex: C2A0) ? I've tried everyway I've been able to find to tell the...
1
by: Nagarajan | last post by:
Hello, I am trying to open an application as a VS . NET Project . I get this error every time "Cannot create the offline cache in C:\Documents and Settings\TEMP\My Documents\Visual...
21
by: Dino M. Buljubasic | last post by:
I'd like my application to be able to detect default email application (MS Outlook or whichever is set to be default) so that the user can enter the email body, address, subject line and send the...
6
by: archana | last post by:
Hi all, can someone tell me difference between unicode and utf 8 or utf 18 and which one is supporting more character set. whic i should use to support character ucs-2. I want to use ucs-2...
7
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32,...
35
by: Bjoern Hoehrmann | last post by:
Hi, For a free software project, I had to write a routine that, given a Unicode scalar value U+0000 - U+10FFFF, returns an integer that holds the UTF-8 encoded form of it, for example, U+00F6...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.