Konstruktor ServerDocument — (String, FileAccess)

Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu pełnej ścieżki dokumentu do załadowania i wartość wskazującą, że dostęp do plików dla danego dokumentu.

Przestrzeń nazw:  Microsoft.VisualStudio.Tools.Applications
Zestaw:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (w Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Składnia

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

Parametry

  • documentPath
    Typ: System.String
    Pełna ścieżka dokumentu do załadowania.

Wyjątki

Wyjątek Warunek
ArgumentNullException

documentPath Jest parametr nullodwołanie o wartości null (Nothing w języku Visual Basic) lub pusty lub zawiera tylko znaki odstępu.

ArgumentException

The value of access is System.IO.FileAccess.Write.

FileNotFoundException

W pliku określonym przez documentPath nie istnieje.

DocumentNotCustomizedException

W pliku określonym przez documentPath parametr nie ma pliku dostosowań, a wartość access jest System.IO.FileAccess.Read.

DocumentCustomizedWithPreviousRuntimeException

W pliku określonym przez documentPath ma dostosowania, który nie został utworzony z programu Visual Studio 2010 Tools dla środowiska Office Runtime lub Visual Studio Tools dla pakietu Microsoft Office system (wersja 3.0 Runtime).

UnknownCustomizationFileException

W pliku określonym przez documentPath ma rozszerzenie nazwy pliku, który nie jest obsługiwany przez Visual Studio 2010 Tools for Office Runtime.

Uwagi

Ten konstruktor umożliwia dostęp do pamięci podręcznej danych lub wdrożenia manifestu informacji w dokumencie, który znajduje się na dysku, jeśli chcesz otworzyć dokument z dostępem tylko do odczytu lub tylko do zapisu.Domyślnie, drugi ServerDocument konstruktorów Otwórz dokument z dostępem do odczytu i zapisu.

Przykłady

Następujący kod w przykładzie wykorzystano ServerDocument(String, FileAccess) Konstruktor, aby utworzyć nową ServerDocument który ładuje określonego dokumentu z dostępem tylko do odczytu.Następnie kod wyświetla adres URL manifestu wdrażania dla dostosowania, który jest dołączony do dokumentu.

W tym przykładzie wymaga:

  • Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.

  • Odwołania do następujących zestawów:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli cele projektu .NET Framework 4 lub .NET Framework 4.5).

      lub

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Jeśli projekt jest przeznaczony dla.NET Framework 3.5).

  • Imports(dla Visual Basic) lub using (w przypadku C#) oświadczenia dla Microsoft.VisualStudio.Tools.Applications i Microsoft.VisualStudio.Tools.Applications.Runtime obszarów nazw u góry pliku kodu.

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();
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ServerDocument Klasa

Przeciążenie ServerDocument

Przestrzeń nazw Microsoft.VisualStudio.Tools.Applications