How to open in default browser in C#

ID : 10092

viewed : 58

Tags : c#browserwindowdefaultnew-operatorc#

Top 5 Answer for How to open in default browser in C#

vote vote


You can just write


EDIT: The WebBrowser control is an embedded copy of IE.
Therefore, any links inside of it will open in IE.

To change this behavior, you can handle the Navigating event.

vote vote


For those finding this question in dotnet core. I found a solution here


private void OpenUrl(string url) {     try     {         Process.Start(url);     }     catch     {         // hack because of this:         if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))         {             url = url.Replace("&", "^&");             Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });         }         else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))         {             Process.Start("xdg-open", url);         }         else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))         {             Process.Start("open", url);         }         else         {             throw;         }     } } 
vote vote


public static void GoToSite(string url) {      System.Diagnostics.Process.Start(url); } 

that should solve your problem

vote vote


After researching a lot I feel most of the given answer will not work with dotnet core. 1.System.Diagnostics.Process.Start(""); -- Will not work with dotnet core

2.It will work but it will block the new window opening in case default browser is chrome

 myProcess.StartInfo.UseShellExecute = true;      myProcess.StartInfo.FileName = "http://some.domain.tld/bla";     myProcess.Start(); 

Below is the simplest and will work in all the scenarios.

Process.Start("explorer", url); 
vote vote


Did you try Processas mentioned here:

You could use

Process myProcess = new Process();  try {     // true is the default, but it is important not to set it to false     myProcess.StartInfo.UseShellExecute = true;      myProcess.StartInfo.FileName = "http://some.domain.tld/bla";     myProcess.Start(); } catch (Exception e) {     Console.WriteLine(e.Message); } 

Top 3 video Explaining How to open in default browser in C#