简体   繁体   中英

Exception reading *.htm file from local app data (Metro App)

I'm using FileIO.ReadTextAsync() to read an *.htm webpage which I have saved into "ms-appdata:///local", using Utf8 encoding.

But I get a System.ArgumentOutOfRangeException when doing it. Additional information is No mapping for the Unicode character exists in the target multi-byte code page .

Reading an ordinary *.txt file using the same function works fine. What am I doing wrong ?

Edit : Code

async private void Button_Click(object sender, RoutedEventArgs e)
{
StorageFile SF = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/test3.html"));
string html = await FileIO.ReadTextAsync(SF, Windows.Storage.Streams.UnicodeEncoding.Utf8);
}

Change the file encoding using Visual Studio. When I opened the file it had the encoding: "Western European (Windows) - Codepage 1252"

  1. Open the file in Visual Studio
  2. File > Advanced Save Options... >
  3. Change the encoding to "Unicode (UTF-8 with signature) - Codepage 65001" 进阶储存选项
  4. Save the file

Credits: Advanced save options in visual studio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM