I would like to read a CSV file in my javascript written windows store app. If I use readTextAsync I get an error when using some german umlauts.
No mapping for the Unicode character exists in the target multi-byte code page.
I found a solution in C# here ReadText from file in ANSII encoding but I have no idea how to solve it in JavaScript?
Is there someting like the Encoding class in JavaScript? If I convert the file to UTF8 it works fine, but my customer would like to use a file saved by excel. Excel does not use UTF8 by default.
The simplest would be to convert the file to UTF-8 as that's easily accessed by WinJS.
There isn't an equivalent to the code exactly in the WinJS library that you found for C# (for some reason, it's not exposed). There are only simple encodings available for UTF-8/16(L/H).
So, if you don't want to convert the file and you're using JavaScript, I'd create a simple Windows Runtime Component (walkthrough) that contains the behavior you want. It's quite simple if you follow the walkthrough. Basically, you write some code in C#, and when done per the rules, it becomes available in WinJS as a component. The code you'd need to write is relatively straightforward as well:
As the
Task
class isn't available in WinJS, it returns an interfaceIAsyncOperation<T>
that is automatically wrapped by aPromise
in WinJS.I've only tested it a tiny bit, but it should help you on your way:
Valid encodings are in the table on this page.