C# Tips

C# Tip Article

C# : How to launch browser and visit web site?

Question

In C# desktop application, how can we launch browser and navigate to a specifc web site URL?

Tip

In order to navigate to a specific URL, we can launch any browser with URL as a command parameter. For example, to launch Chrome and visit Amazon, we can say:

     C:\>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" amazon.com

To implement this in C#, basically we can create new process for a internet browser and set the given URL as a process parameter.

// In case of Internet Explorer
Process.Start("IExplore.exe", "csharp.tips");

// In case of Google Chrome
Process.Start("Chrome.exe", "csharp.tips");

One caveat for this approach is you never know if the application user has IE or chrome or any other browser on user's machine. (If user does not have browser at all, then of course s/he will get an error. We generally don't worry about this.)

So better way is probably we can launch default browser by simply passing http url as below.

// Use default browser
Process.Start("http://csharp.tips");

Answer

Launch default browser by passing URL in Process.Start(url).

// Use default browser
Process.Start("http://csharp.tips");