C # - How to open a html file in a web browser that is not standard?

I am trying to open a html file in a web browser that is not standard. So far, I can open the html file in the default web browser:

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

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

It would be great if I could get the webBrowser object by this process. I've already found how to detect if my desired web browser is opening:

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

Also I cannot change the default web browser, I will use the application on my school computer.

thank

+3


source to share


3 answers


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 are trying to open some kind of 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);
}

      

+2


source


You can use the code below:

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

      

+2


source


try it

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

      

See Microsoft article about it

0


source







All Articles