Opening Files, Applications, Web Documents, and the Mail Client

Opening a File

Imports System.Diagnostics

⋮

Dim psi As New ProcessStartInfo()
psi.UseShellExecute = True
psi.FileName = "C:\bla.html"
Process.Start(psi)

Starting an Application

If you want to start an application, you can simply call System.Diagnostics.Process.Start("C:\bla.exe") or Shell("C:\bla.exe") in Visual Basic .NET.

Opening a Webpage in the Default Browser

For starting the system’s default browser with a predefined URL, specify the URL you want to be displayed instead of the filename in the code listed above.

The code below can be used to start a new instance of Internet Explorer and display a certain webpage:

Imports System.Diagnostics

⋮

Dim psi As New ProcessStartInfo()
With psi
    .FileName = "iexplore"
    .Arguments = "-new https://dotnet.currifex.org/"
End With
Process.Start(psi)

Opening the Default E-Mail Client with a Template

Sample based on work by Fergus Cooney and Cor Ligthert [MVP]:

Add a reference to System.Web.dll. Then you can use this code:

Imports System.Diagnostics
Imports System.Web

⋮

Public Sub StartDefaultMail( _
    ByVal [To] As String, _
    Optional ByVal Subject As String = "", _
    Optional ByVal Message As String = "" _
)
    Try
        Dim psi As New ProcessStartInfo()
        psi.UseShellExecute = True
        psi.FileName = _
             "mailto:" & HttpUtility.UrlEncode([To]) & _
             "?subject=" & HttpUtility.UrlEncode(Subject) & _
             "&body=" & HttpUtility.UrlEncode(Message)
        Process.Start(psi)
    Catch ex As Exception
        Throw _
            New ApplicationException( _
                "Default mail client could not be started.", _
                ex _
            )
    End Try
End Sub

Usage:

StartDefaultMail( _
    "foo@goo.baz", _
    "Invitation", _
    "Do you want to come to my party?" _
)