How do you open a local html file in a web browser when the path contains an url fragment

牧云@^-^@ 提交于 2019-12-06 10:49:41

Thanks to all that tried to help me with this issue. I have since found a solution that works. I have posted it below. All you need to do is call navigate with a local file path containing a fragment. Cheers!

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

All you need is:

System.Diagnostics.Process.Start(url);
user424678

I am not a C# programmer, but in PHP I would do a urlencode. When I did a Google search on C# and urlencode it gave this page here at StackOverflow... url encoding using C#

Try relying on the system to resolve things correctly:

    static void Main(string[] args)
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = true;
        p.StartInfo.FileName = "http://stackoverflow.com/questions/tagged/c%23?sort=newest&pagesize=50";
        p.StartInfo.Verb = "Open";
        p.Start();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!