当路径包含 url 片段时,如何在 Web 浏览器中打开本地 html 文件

use*_*450 3 c# fragment process.start

我正在尝试通过以下方法打开网络浏览器。但是,当浏览器打开 url / 文件路径时,片段被损坏(从“#anchorName”到“%23anchorName”),这似乎没有得到处理。所以基本上,文件打开但不会跳转到文档中的适当位置。有谁知道如何打开文件并处理片段?对此的任何帮助将不胜感激。

打开的示例路径是“c:\MyFile.Html#middle”

    // calls out to the registry to get the default browser
    private static string GetDefaultBrowserPath()
    {
       string key = @"HTTP\shell\open\command";
       using(RegistryKey registrykey = Registry.ClassesRoot.OpenSubKey(key, false))
       {
          return ((string)registrykey.GetValue(null, null)).Split('"')[1];
       }
    }

    // creates a process and passes the url as an argument to the process
    private static void Navigate(string url)
    {
       Process p = new Process();
       p.StartInfo.FileName = GetDefaultBrowserPath();
       p.StartInfo.Arguments = url;
       p.Start();
    }
Run Code Online (Sandbox Code Playgroud)

use*_*450 5

感谢所有试图帮助我解决这个问题的人。从那以后,我找到了一个有效的解决方案。我已经把它贴在下面了。您需要做的就是使用包含片段的本地文件路径调用导航。干杯!

    private static string GetDefaultBrowserPath()
    {
       string key = @"HTTP\shell\open\command";
       using(RegistryKey registrykey = Registry.ClassesRoot.OpenSubKey(key, false))
       {
          return ((string)registrykey.GetValue(null, null)).Split('"')[1];
       }
    }

    private static void Navigate(string url)
    {
       Process.Start(GetDefaultBrowserPath(), "file:///{0}".FormatWith(url));
    }
Run Code Online (Sandbox Code Playgroud)