Problem

The following code to read the text contents of a file in WinRT thru an exception on some txt files and not on others.
var localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; var file = await localFolder.GetFileAsync("Sample.txt"); var stringContent = await Windows.Storage.FileIO.ReadTextAsync(file);
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code WinRT information: No mapping for the Unicode character exists in the target multi-byte code page. Additional information: No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459) If there is a handler for this exception, the program may be safely continued.
Solution 1 - Remove all the problem characters
The following line in the txt file was causing the issue:
Rangitoto ki te Tonga/D’Urville Island
Changing the ’ to a ' resolved the issue.
In another text file I also needed to change a – to -.
Solution 2
Change the file encoding using Visual Studio. When I opened the file it had the encoding: "Western European (Windows) - Codepage 1252"
- Open the file in Visual Studio
- File > Advanced Save Options... >
- Change the encoding to "Unicode (UTF-8 with signature) - Codepage 65001"
- Save the file
thanks.
ReplyDeleteThanks that really helped !
ReplyDeletethanks!!
ReplyDeleteThank you very much
ReplyDeleteYou are great man. Thank You!!!
ReplyDeleteThank you!
ReplyDeleteHello Daniel, I prefer the second one but how to use western Europe 1252 codepage when I try to open fil with C# program writed with Visual studio 2015 (Framework .NET 4.6).
ReplyDeleteAm I oblige to use utf8 ? I yes, I have to save my Excel file with this last codepage. How to do that...I'm searching
Otherwise, could I use the European codepage 1252 with my program when I try to open then read a file...I'm searching also...