I'm using this to get the path and executable of default web browser:
public static string DefaultWebBrowser
{
get
{
string path = @"\http\shell\open\command";
using (RegistryKey reg = Registry.ClassesRoot.OpenSubKey(path))
{
if (reg != null)
{
string webBrowserPath = reg.GetValue(String.Empty) as string;
if (!String.IsNullOrEmpty(webBrowserPath))
{
if (webBrowserPath.First() == '"')
{
return webBrowserPath.Split('"')[1];
}
return webBrowserPath.Split(' ')[0];
}
}
return null;
}
}
}
And:
protected static bool Run(string FileName, string Args)
{
try
{
Process proc = new Process();
processInfo.FileName = FileName;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
if(Args != null) proc.StartInfo.Arguments = Args;
proc.Start();
return true;
}
catch (Exception) { }
return false;
}
Then I call the web browser: Run(DefaultWebBrowser, "foo.html")
The question is: the above function is calling Firefox and IE (the two web browsers installed on my pc) instead of Internet Explorer, the default web browser. I have no idea how to fix this.
EDIT
I have downloaded and installed the Google Chrome, set it as default web browser, but oddly the above error don't happens with it.
Fire up Chrome and jump to the webpage you want to view the HTML source code. Right-click the page and click on “View Page Source,” or press Ctrl + U, to see the page's source in a new tab. A new tab opens along with all the HTML for the webpage, completely expanded and unformatted.
Check if the file is saved with a UTF-8 encoding. If that doesn't work, try installing another browser or using Edge/Safari/Internet Explorer or whatever built-in browser you have. It is saved as index.
The file at file:///Users/.../index.html is not readable. It may have been removed, moved, or file permissions may be preventing access. Community content may not be verified or up-to-date.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With