Freigeben über


ServerDocument-Konstruktor (String, FileAccess)

Initialisiert eine neue Instanz der ServerDocument-Klasse und verwendet dabei den vollständigen Pfad zu dem Dokument, das geladen werden soll, sowie einen Wert, der den Dateizugriff für das Dokument angibt.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntax

'Declaration
Public Sub New ( _
    documentPath As String, _
    access As FileAccess _
)
public ServerDocument(
    string documentPath,
    FileAccess access
)

Parameter

  • documentPath
    Typ: System.String
    Der vollständige Pfad des Dokuments, das geladen werden soll.

Ausnahmen

Ausnahme Bedingung
ArgumentNullException

Der documentPath-Parameter ist entweder nullein Nullverweis (Nothing in Visual Basic) oder leer, oder er besteht nur aus Leerzeichen.

ArgumentException

Der Wert von access ist System.IO.FileAccess.Write.

FileNotFoundException

Die in documentPath angegebene Datei ist nicht vorhanden.

DocumentNotCustomizedException

Die im documentPath-Parameter angegebene Datei hat keine Anpassung, und der Wert von access ist System.IO.FileAccess.Read.

DocumentCustomizedWithPreviousRuntimeException

Die von documentPath angegebene Datei bietet eine Anpassung, die nicht mit der Visual Studio 2010-Tools für Office-Laufzeit oder den Visual Studio-Tools für das Microsoft Office-System (Version 3.0 Laufzeit) erstellt wurde.

UnknownCustomizationFileException

Die in documentPath angegebene Datei hat eine Dateinamenerweiterung, die nicht von Visual Studio-Tools für Office-Laufzeit unterstützt wird.

Hinweise

Verwenden Sie diesen Konstruktor, um auf die zwischengespeicherten Daten oder die Informationen zum Bereitstellungsmanifest in einem Dokument zuzugreifen, das sich auf einem Datenträger befindet, wenn Sie das Dokument nur mit Lesezugriff oder nur mit Schreibzugriff öffnen möchten.Standardmäßig öffnen die anderen ServerDocument-Konstruktoren das Dokument mit Lese-/Schreibzugriff.

Beispiele

Im folgenden Codebeispiel wird der ServerDocument(String, FileAccess)-Konstruktor zum Erstellen eines neuen ServerDocument-Objekts verwendet, das ein angegebenes Dokument mit Lesezugriff lädt.Im Code wird dann die URL des Bereitstellungsmanifests für die Anpassung angezeigt, die an das Dokument angefügt ist.

Dieses Beispiel setzt Folgendes voraus:

  • Ein Konsolenanwendungsprojekt oder ein anderes Nicht-Office-Projekt.

  • Verweise auf die folgenden Assemblys:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll und Microsoft.VisualStudio.Tools.Applications.Runtime.dll (wenn das Projekt .NET Framework 4 oder .NET Framework 4.5 abzielt).

      oder

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll und Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (wenn das Projekt auf .NET Framework 3.5 abzielt).

  • Imports-Anweisungen (für Visual Basic) oder using-Anweisungen (für C#) für Microsoft.VisualStudio.Tools.Applications- und Microsoft.VisualStudio.Tools.Applications.Runtime-Namespaces am Anfang der Codedatei.

Private Sub CreateServerDocumentReadOnly(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            serverDocument1 = New ServerDocument(documentPath, System.IO.FileAccess.Read)
            MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                serverDocument1.DeploymentManifestUrl.ToString())
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As DocumentNotCustomizedException
        System.Windows.Forms.MessageBox.Show("The specified document does not " & _
            "have a customization.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Finally
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentReadOnly(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath,
                System.IO.FileAccess.Read);
            MessageBox.Show("The URL of the deployment manifest is: \n" +
                serverDocument1.DeploymentManifestUrl.ToString());
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (DocumentNotCustomizedException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not " +
            "have a customization.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

.NET Framework-Sicherheit

Siehe auch

Referenz

ServerDocument Klasse

ServerDocument-Überladung

Microsoft.VisualStudio.Tools.Applications-Namespace