I\'m using this to get the path and executable of default web browser:
public static string DefaultWebBrowser
{
get
{
Im using a code, where i look up for exe files first. For example, if exsists chrome.exe (in its default path) else if exists firefox.exe or launcher.exe (for opera) etc... if doesnt any exists, try to run iexplore.exe with pathToHtmlFile parameter. This is my solution, where i use external config, where a set my browser, doesnt matter what is set default in OS.
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.
For .Net Core you need to call (suggested in .Net Core 2.0 Process.Start throws "The specified executable is not a valid application for this OS platform")
var proc = Process.Start(@"cmd.exe ", @"/c " + pathToHtmlFile);
When I tried Process.Start(pathToHtmlFile);
,
I've got System.ComponentModel.Win32Exception: The specified executable is not a valid application for this OS platform.
For those who don't have html default association to a browser, use
System.Diagnostics.Process.Start("Chrome", Uri.EscapeDataString(pathToHtmlFile))