【问题标题】:How to open a local html file using NavigationWindow when path contains URL fragment?当路径包含 URL 片段时,如何使用 NavigationWindow 打开本地 html 文件?
【发布时间】:2014-01-15 14:56:58
【问题描述】:

我正在使用NavigationWindow 来显示 html 文件,它工作正常,直到路径不包含任何 # 或非法字符。

我只是想知道当路径包含 URL 片段时,有没有办法打开 html 文件,例如:如下所示的锚点 #..

"c:\MyFile.Html#tips"

目前我遇到以下异常...

Could not find file 'c:\MyFile.Html#tips'
System.Net.WebException was unhandled 

  HResult=-2146233079

【问题讨论】:

    标签: c# wpf anchor navigationwindow


    【解决方案1】:

    问题在于 URI 的创建,似乎 URI 类存在一些错误。

    下面生成的URI不一样,

    var filePath = @"c:\MyFile.Html#tips";   
    var uri = new Uri(filePath);
    var uri2 = new Uri("file://" + filePath);
    

    uri 的片段部分为空,但uri2 的片段部分正确为“#tips”。

    即使在创建 URI 为uri2 之后,查询也会出现同样的问题,报告的查询错误 字符串可以在这里找到,Why doesn't System.Uri recognize query parameter for local file path?Uri class does not parse filesystem URL with query string

    【讨论】:

      猜你喜欢
      • 2011-11-04
      • 2015-05-10
      • 2013-09-09
      • 2014-12-13
      • 2014-04-27
      • 2017-02-28
      • 2015-08-25
      • 1970-01-01
      • 2014-06-03
      相关资源
      最近更新 更多