locked
FileIO.readTextAsync(file) doesn't read csv/txt files exported with excel

    Question

  • Hi guys,

    i'm using the Windows.FileIO.readTextAsync(file).done(...) method to read the text from csv files. If I Export files from Excel as csv the function throws an error:

    "No mapping for the Unicode character exists in the target multi-byte code page"

    If I open the exported file in Editor and re-save it, it is read without any Problems. Is there a better solution for this?

    Thanks a lot

    Dragon


    Friday, November 14, 2014 4:44 PM

Answers

  • That means you have a file which appears to be a non-Unicode but has some characters which aren't valid in the current code-page. The best way to fix this is to save the file originally as UTF-8 with a byte-order-mark (BOM). If you know that the file is UTF-8 but doesn't have a BOM then you can explicitly read it as UTF-8 by passing the UnicodeEncoding.utf8 to readTextAsync.
    Saturday, November 15, 2014 2:38 AM
    Owner

All replies

  • That means you have a file which appears to be a non-Unicode but has some characters which aren't valid in the current code-page. The best way to fix this is to save the file originally as UTF-8 with a byte-order-mark (BOM). If you know that the file is UTF-8 but doesn't have a BOM then you can explicitly read it as UTF-8 by passing the UnicodeEncoding.utf8 to readTextAsync.
    Saturday, November 15, 2014 2:38 AM
    Owner
  • Thanks for your fast answer.

    I found out, that Excel is the reason for the error. I made the CSV file with copy and paste. I pasted data from an xlsx to an new file and saved it as CSV.

    If I choose 'Values' ('Werte' in the german version) in Excels Paste-Dialog and save the file as CSV it works. Otherwise it won't. I think Excel saves some invisible data to the file which cause the error. Strange!

    Thanks a lot!

    Saturday, November 15, 2014 9:25 AM