Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Opening UTF-8 file result in strange chars

Reply
Thread Tools

Opening UTF-8 file result in strange chars

 
 
Lasse Edsvik
Guest
Posts: n/a
 
      09-03-2007
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


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      09-03-2007
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)
 
Reply With Quote
 
 
 
 
Lasse Edsvik
Guest
Posts: n/a
 
      09-03-2007
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." <(E-Mail Removed)> 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)



 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-03-2007
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/
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-03-2007
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)
 
Reply With Quote
 
Lasse Edsvik
Guest
Posts: n/a
 
      09-04-2007
That's exactly the code I'm using...


"Evertjan." <(E-Mail Removed)> 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/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)



 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      09-04-2007
"Lasse Edsvik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to truncate char string fromt beginning and replace chars instring by other chars in C or C++? Hongyu C++ 9 08-08-2008 12:18 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
Word file not opening from Adm -My recent docs but opening from file menu of Word Thaqalain Computer Support 0 06-30-2005 02:20 AM
receiving ??? chars instead of "special" chars M.Posseth ASP .Net Web Services 3 11-16-2004 07:00 PM



Advertisments