Opening UTF-8 file result in strange chars

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lasse Edsvik

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


  • Evertjan.

    #2
    Re: Opening UTF-8 file result in strange chars

    Lasse Edsvik wrote on 03 sep 2007 in
    microsoft.publi c.inetserver.as p.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 filesystemobjec t. 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)

    Comment

    • Lasse Edsvik

      #3
      Re: Opening UTF-8 file result in strange chars

      Evertjan,

      as a tested with:

      (file is saved as UTF-8 )

      <%
      Set fs=Server.Creat eObject("Script ing.FileSystemO bject")

      Set f=fs.OpenTextFi le(Server.MapPa th("/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.100 procent.com


      the file contains:

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







      "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
      news:Xns99A0ABB D13C87eejj99@19 4.109.133.242.. .
      Lasse Edsvik wrote on 03 sep 2007 in
      microsoft.publi c.inetserver.as p.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 filesystemobjec t. 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)

      Comment

      • Martin Honnen

        #4
        Re: Opening UTF-8 file result in strange chars

        Lasse Edsvik wrote:
        as a tested with:
        >
        (file is saved as UTF-8 )
        >
        <%
        Set fs=Server.Creat eObject("Script ing.FileSystemO bject")
        FileSystemObjec t 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

        Comment

        • Evertjan.

          #5
          Re: Opening UTF-8 file result in strange chars

          Lasse Edsvik wrote on 03 sep 2007 in
          microsoft.publi c.inetserver.as p.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.Creat eObject("Script ing.FileSystemO bject")
          Read this:

          Gain technical skills through documentation and training, earn certifications and connect with the community

          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)

          Comment

          • Lasse Edsvik

            #6
            Re: Opening UTF-8 file result in strange chars

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


            "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
            news:Xns99A0B28 A2C8FCeejj99@19 4.109.133.242.. .
            Lasse Edsvik wrote on 03 sep 2007 in
            microsoft.publi c.inetserver.as p.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.Creat eObject("Script ing.FileSystemO bject")
            >
            Read this:
            >
            Gain technical skills through documentation and training, earn certifications and connect with the community

            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)

            Comment

            • Anthony Jones

              #7
              Re: Opening UTF-8 file result in strange chars

              "Lasse Edsvik" <lasse@nospam.c omwrote in message
              news:O96eKbs7HH A.5316@TK2MSFTN GP04.phx.gbl...
              That's exactly the code I'm using...
              >

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

              Dim oStream : oStream = Server.CreateOb ject("ADODB.Str eam")

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

              Response.Write oStream.ReadTex t

              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.Conten tType = "text/csv"
              Response.CharSe t = "UTF-8"

              Dim oStream : oStream = Server.CreateOb ject("ADODB.Str eam")

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

              Response.Binary Write 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


              Comment

              Working...