How to launch a web browser in C#

Posted: (EET/GMT+2)

 

I needed a very simple piece of C# code: I wanted to launch a web browser with a given URL when the user clicked a picture in my WinForms application.

Initially, I didn't seem to find the correct keywords to find a solution with Google, but finally I did.

So, I'm sharing the code that I learned today:

private static void LaunchWebBrowser()
{
  const string MY_URL = "http://www.saunalahti.fi/janij/";
  // launch web browser
  System.Diagnostics.ProcessStartInfo startInfo =
    new ProcessStartInfo();
  startInfo.UseShellExecute = true;
  startInfo.FileName = MY_URL;
  System.Diagnostics.Process.Start(startInfo);
}

Keywords for this sample code: open web browser, C#, example code, launch web page from Windows application.