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

100

You can just write

System.Diagnostics.Process.Start("http://google.com"); 

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

82

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

Code:

private void OpenUrl(string url) {     try     {         Process.Start(url);     }     catch     {         // hack because of this: https://github.com/dotnet/corefx/issues/10361         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

73

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

that should solve your problem

vote vote

60

After researching a lot I feel most of the given answer will not work with dotnet core. 1.System.Diagnostics.Process.Start("http://google.com"); -- 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

54

Did you try Processas mentioned here: http://msdn.microsoft.com/de-de/library/system.diagnostics.process.aspx?

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#

Related QUESTION?