Cannot read chinese characters from CSV files RRS feed

  • Question

  • User-1140746197 posted
    <!-- / icon and title --><!-- message -->
    I import the CSV in the database and I use dataTable to read the contents of CSV file first. The CSV files contains both english and traditional chinese characters. However, after importing the csv, the chinese characters are all mess code. I would like to know how to correct the encoding of the CSV file to make it able to store the chinese characters.
     string content = File.ReadAllText(SaveLocation);
    Thank you
    Thursday, December 21, 2006 3:57 AM

All replies

  • User1416329745 posted

    You need to save the CVS file in note pad as Unicode and not ASCII and use the correct Chinese collation in the database and in 2005 use collation precedence in your query. The correct collations are in the link below, post again if you still have questions. Hope this helps.



    Thursday, December 21, 2006 5:11 PM
  • User-1140746197 posted

    Thank you for your answer.

    It really waorks if i use notepad to make a csv file.

    However, using notepad is really not convenience to the user. I would like to know how i can use excel to do this. It seems that Excel doesn't really care about the encodng.

    Thank you.

    Friday, December 22, 2006 4:13 AM
  • User1416329745 posted

    Excel actually makes it easier just change your encoding code to the one I posted in the thread below.  Hope this helps.


    Friday, December 22, 2006 8:36 AM
  • User-1140746197 posted

    Thank you for your answer.

     Since I would like to import the CSV files to the gridview and database, I have prepared the CSV files through Excel. I would like to create the excel file using Microsoft Excel instead of exporting the data from gridview. Is there any way to set the encoding in Excel?

    Thank you

    Saturday, December 23, 2006 11:27 AM
  • User1416329745 posted
    All Excel code comes with the line (Response.Charset = "" ) you have to change that to Response.ContentEncoding = System.Text.Encoding.UTF7 and it will solve your problem, if you look at the code in the link below doing what you want you will see the line of code that needs to be changed.  Hope this helps.
    Saturday, December 23, 2006 11:59 AM