Open a URL from Windows Forms

.NetWinforms

.Net Problem Overview


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?

.Net Solutions


Solution 1 - .Net

This article will walk you through it.

Short answer:

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

Solution 2 - .Net

using System.Diagnostics;

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

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

Solution 3 - .Net

For those getting a "Win32Exception: The System cannot find the file specified"

This should do the work:

ProcessStartInfo psInfo = new ProcessStartInfo
{
   FileName = "https://www.google.com",
   UseShellExecute = true
};
Process.Start(psInfo);

UseShellExecute is descriped further here

For me the issue was due to the .NET runtime as descriped here

Solution 4 - .Net

Here is the best of both worlds:

Dim sInfo As New ProcessStartInfo("http://www.mysite.com")

Try
     Process.Start(sInfo)
Catch ex As Exception
     Process.Start("iexplore.exe", sInfo.FileName)
End Try

I found that the answer provided by Blorgbeard will fail when a desktop application is run on a Windows 8 device. To Camillo's point, you should attempt to open this with the user's default browser application, but if the browswer application is not assigned, an unhandled exception will be thrown.

I am posting this as the answer since it handles the exception while still attempting to open the link in the default browser.

Solution 5 - .Net

I like approach described here. It takes into account possible exceptions and delays when launching the 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 the browser to navigate him to the url failed).

Solution 6 - .Net

The above approach is perfect, I would like to recommend this approach to where you can pass your parameters.

Process mypr;
mypr = Process.Start("iexplore.exe", "pass the name of website");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdrian ClarkView Question on Stackoverflow
Solution 1 - .NetBlorgbeardView Answer on Stackoverflow
Solution 2 - .NetAaron WagnerView Answer on Stackoverflow
Solution 3 - .NetDanielView Answer on Stackoverflow
Solution 4 - .NetRogalaView Answer on Stackoverflow
Solution 5 - .NetSumrakView Answer on Stackoverflow
Solution 6 - .NetammrinView Answer on Stackoverflow