Open a html file using default web browser

前端 未结 4 899
执笔经年
执笔经年 2021-01-04 00:57

I\'m using this to get the path and executable of default web browser:

public static string DefaultWebBrowser
        {
            get
            {

               


        
4条回答
  •  旧巷少年郎
    2021-01-04 01:11

    You can replace all that code with

    System.Diagnostics.Process.Start(pathToHtmlFile);
    

    This will automatically start your default browser, or rather look up the default handler for .htm or .html files and use that.

    Now with Firefox set as default this can sometimes cause weird exceptions (I think if Firefox is starting for first time), so you might want to do a try/catch on it to handle that.

提交回复
热议问题