我正在尝试通过以下方法打开Web浏览器。然而,当浏览器打开URL /文件路径时,片段部分会被破坏(从“#anchorName”变为“%23anchorName”),似乎无法处理。因此,文件会打开,但不会跳转到文档中的适当位置。有人知道如何打开文件并处理片段吗?对此的任何帮助将不胜感激。
要打开的示例路径为“c:\ MyFile.Html#middle”。
要打开的示例路径为“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();
}