tags:

views:

2214

answers:

3

I'm trying to provide a link to my company's website from a Windows Form. I want to be well behaved and launch using the user's preferred browser.

What is the best way to open a URL in the user's default browser from a Windows Forms application?

+3  A: 
using System.Diagnostics;

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

This approach has worked for me, but I could be missing something important.

Aaron Wagner
+9  A: 

This article will walk you through it.

Short answer:

ProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/");  
Process.Start(sInfo);
Blorgbeard
A: 

I like approach described link text. It takes into account possible exceptions and delays when launching browser.

For best practice make sure you don't just ignore the exception, but catch it and perform an appropriate action (for example notify user that opening browser to navigate him to the url failed).

Ornus
True, and that you should always consider. Their method of just swallowing exceptions makes me cringe though. You may be able to make arguments for it in this specific case but I'd still never have an empty "catch" block. It is too easy to entirely mask an issue that way.
Aydsman
you're right. I didn't actually think about possible exception (and I should've) until I saw the post.
Ornus