Marc-Antoine Charland
Marc-Antoine Charland

Reputation: 95

c# - How to open a local html file in a web browser that is not the default one?

I am trying to open a local html file in a web browser that is not the default one. Up to now, I can open an html file in the default web browser with :

System.Diagnostics.Process.Start(" File location ");

But is there a way to open this file in a web browser that is not the default?

It would be great if I can obtain a webBrowser object by the process. I already find how to determine if the desired web browser is opened with:

var runningProcess = System.Diagnostics.Process.GetProcessesByName("chrome"); if (runningProcess.Length != 0) { }

Also I can't change the default web browser.

Thanks

Upvotes: 3

Views: 5187

Answers (3)

Mitz
Mitz

Reputation: 561

Try this

ProcessStartInfo sInfo = new ProcessStartInfo("http://url.com/");  
Process.Start(sInfo);

See the microsoft article about this

Upvotes: 0

garethb
garethb

Reputation: 4051

If you want to open a website in chrome from c#, try:

System.Diagnostics.Process.Start("chrome", "www.google.com");

Using your code, I think you're trying to get any open browser first?

var runningProcess = System.Diagnostics.Process.GetProcessesByName("chrome");
if (runningProcess.Length != 0)
{
    System.Diagnostics.Process.Start("chrome", filename);
}
runningProcess = System.Diagnostics.Process.GetProcessesByName("firefox");
if (runningProcess.Length != 0)
{
    System.Diagnostics.Process.Start("firefox", filename);
}
runningProcess = System.Diagnostics.Process.GetProcessesByName("iexplore");
if (runningProcess.Length != 0)
{
    System.Diagnostics.Process.Start("iexplore", filename);
}

Upvotes: 2

Pankaj Kapare
Pankaj Kapare

Reputation: 7812

You can use below code:

Online page :

System.Diagnostics.Process.Start("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "http://wwww.testdomain.com/mypage.html");

Offline Page:

System.Diagnostics.Process.Start("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "C:\Users\AppData\Local\Temp\mypage.html");

Upvotes: 3

Related Questions