Sdílet prostřednictvím


ServerDocument – konstruktor (String, FileAccess)

Inicializuje novou instanci ServerDocument pomocí třídy úplnou cestu k načtení dokumentu a hodnota označuje přístup k souborům pro dokument.

Obor názvů:  Microsoft.VisualStudio.Tools.Applications
Sestavení:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (v Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntaxe

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

Parametry

  • documentPath
    Typ: System.String
    Úplná cesta k načtení dokumentu.

Výjimky

Výjimka Podmínka
ArgumentNullException

documentPath Je parametr nullodkaz Null (Nothing v jazyce Visual Basic) nebo prázdné nebo je celá tvořena bílých znaků.

ArgumentException

Hodnota access je System.IO.FileAccess.Write.

FileNotFoundException

Určený soubor documentPath neexistuje.

DocumentNotCustomizedException

Soubor určený documentPath nemá hodnotu a přizpůsobení, access je System.IO.FileAccess.Read.

DocumentCustomizedWithPreviousRuntimeException

Určený soubor documentPath má vlastní nastavení, který byl vytvořen pomocí Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime).

UnknownCustomizationFileException

Určený soubor documentPath má příponu, která není podporována Visual Studio Tools for Office runtime.

Poznámky

Použijte tento konstruktor přístup dat nebo nasazení manifestu informace v mezipaměti v dokumentu, který je na disku, pokud chcete dokument otevřít s přístupem jen pro čtení nebo jen pro zápis. Standardně druhé ServerDocument konstruktory otevřete dokument pro čtení / zápis.

Příklady

Následující kód například použití ServerDocument(String, FileAccess) konstruktor pro vytvoření nového ServerDocument , načte zadaný dokument jen pro čtení přístup. Kód poté zobrazí adresu URL manifestu nasazení vlastního nastavení, který je připojen k dokumentu.

Tento příklad vyžaduje:

  • Projekt aplikace konzoly nebo některé jiné-Office project.

  • Odkazy na následující sestavení:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud cíle projektu .NET Framework 4).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud cíle projektu.NET Framework 3.5).

  • Imports(pro Visual Basic) nebo using (pro C#) pro příkazy Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů v horní části souboru kódu.

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

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

ServerDocument Třída

ServerDocument – přetížení

Microsoft.VisualStudio.Tools.Applications – obor názvů