Open a webpage in the default browser
This should work:
Dim webAddress As String = "http://www.example.com/"
Process.Start(webAddress)
Here is a little sub that may just interest some people who need to specify the browser. (but its not as good as a 12" pizza sub!) :P
Private Sub NavigateWebURL(ByVal URL As String, Optional browser As String = "default")
If Not (browser = "default") Then
Try
'// try set browser if there was an error (browser not installed)
Process.Start(browser, URL)
Catch ex As Exception
'// use default browser
Process.Start(URL)
End Try
Else
'// use default browser
Process.Start(URL)
End If
End Sub
Call: will open www.google.com in Firefox if it is installed on that PC.
NavigateWebURL("http://www.google.com", "Firefox") '// safari Firefox chrome etc
Call: will open www.google.com in default browser.
NavigateWebURL("http://www.google.com", "default")
OR
NavigateWebURL("http://www.google.com")
As others have indicated, Process.Start()
is the way to go here. However, there are a few quirks. It's worth your time to read this blog post:
http://faithlife.codes/blog/2008/01/using_processstart_to_link_to/
In summary, some browsers cause it to throw an exception for no good reason, the function can block for a while on non-UI thread so you need to make sure it happens near the end of whatever other actions you might perform at the same time, and you might want to change the cursor appearance while waiting for the browser to open.