1. Herfried K. Wagner’s VB.Any
  2. .NET
  3. Häufig gestellte Fragen

Öffnen von Dateien, Anwendungen, Dokumenten im Web sowie des Mailclients

Öffnen von Dateien, Anwendungen, Dokumenten im Web sowie des Mailclients
<URL:https://dotnet.currifex.org/dotnet/faqs/openfileappwebpage/de/>
----------------------------------------------------------------------------

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 in VB.NET
'Shell("C:\bla.exe")'.

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 http://dotnet.mvps.org/"
End With
Process.Start(psi)
///

The command-line switches for Internet Explorer are documented here:

Command line switches for Internet Explorer 4.0
<URL:http://support.microsoft.com/?scid=kb;EN-US;178058>

There is an option in Internet Explorer, that, if set, forces new pages to
be opened in an existing instance (browser window) of Internet Explorer:

Description of the Reuse Windows for Launching Shortcuts Setting in
Internet Explorer 5.01
<URL:http://support.microsoft.com/?scid=kb;EN-US;241911>

Opening the default mail client with a mail template:

Sample based on work by Fergus Cooney and Cor Ligthert [MVP], optimized and
extended by Herfried K. Wagner [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?" _
)
///

'mailto' Protocol
<URL:http://msdn.microsoft.com/workshop/networking/predefined/mailto.asp>