【问题标题】:Exception reading *.htm file from local app data (Metro App)从本地应用程序数据(Metro 应用程序)读取 *.htm 文件时出现异常
【发布时间】:2015-01-30 08:24:42
【问题描述】:

我正在使用FileIO.ReadTextAsync() 读取我保存到“ms-appdata:///local”中的 *.htm 网页,使用 Utf8 编码。

但我在执行此操作时会收到 System.ArgumentOutOfRangeException。其他信息是No mapping for the Unicode character exists in the target multi-byte code page

使用相同的函数读取普通的 *.txt 文件可以正常工作。我做错了什么?

编辑:代码

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);
}

【问题讨论】:

  • 你应该添加代码(或最短的例子)来产生这个问题
  • 你是对的 - 现在完成
  • htm 文件实际上是 UTF-8 格式吗?该错误表明它不是。你能分享一个重现问题的文件吗?
  • @RobCaplan-MSFT 大概就是这样;我意识到,即使我让它正常工作,它也无法解决我的目的,所以现在我正在使用来自另一个 Metro 项目 link 的代码将 html 页面从应用程序包之外的本地文件系统加载到 WebView .

标签: c# windows-store-apps microsoft-metro winrt-xaml


【解决方案1】:

使用 Visual Studio 更改文件编码。当我打开文件时,它的编码是:“西欧(Windows)-代码页 1252”

  1. 在 Visual Studio 中打开文件
  2. 文件 > 高级保存选项... >
  3. 将编码更改为“Unicode(带签名的UTF-8)-代码页65001”
  4. 保存文件

致谢:Advanced save options in visual studio

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    相关资源
    最近更新 更多