Sdílet prostřednictvím


ServerDocument Konstruktory

Definice

Přetížení

ServerDocument(String)

Inicializuje novou instanci ServerDocument třídy pomocí úplné cesty k dokumentu, který se má načíst.

ServerDocument(Byte[], String)

Inicializuje novou instanci ServerDocument třídy pomocí pole bajtů, které představuje dokument, který se má načíst, a příponu názvu souboru dokumentu.

ServerDocument(Stream, String)

Inicializuje novou instanci ServerDocument třídy pomocí streamu, který představuje dokument, který se má načíst, a příponu názvu souboru dokumentu.

ServerDocument(String, FileAccess)

Inicializuje novou instanci ServerDocument třídy pomocí úplné cesty k dokumentu, který se má načíst, a hodnoty, která označuje přístup k souboru pro dokument.

ServerDocument(String)

Inicializuje novou instanci ServerDocument třídy pomocí úplné cesty k dokumentu, který se má načíst.

public:
 ServerDocument(System::String ^ documentPath);
public ServerDocument (string documentPath);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (documentPath As String)

Parametry

documentPath
String

Úplná cesta k dokumentu, který se má načíst.

Výjimky

Parametr documentPath je nebo je null prázdný nebo se skládá výhradně z prázdných znaků.

Soubor zadaný nástrojem documentPath neexistuje.

Soubor zadaný nástrojem documentPath má vlastní nastavení, které nebylo vytvořeno pomocí sady Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime).

Soubor zadaný nástrojem documentPath má příponu názvu souboru, kterou modul runtime Visual Studio Tools for Office nepodporuje.

Příklady

Následující příklad kódu používá ServerDocument(String) konstruktor k vytvoření nového ServerDocument , který načte zadaný dokument. Příklad pak zobrazí adresu URL manifestu nasazení pro přizpůsobení, které je připojené k dokumentu.

Tento příklad vyžaduje:

  • Projekt konzolové aplikace nebo jiný projekt mimo sadu Office

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

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud projekt cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud je projekt zaměřen na rozhraní .NET Framework 3.5).

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

private void CreateServerDocumentFromPath(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath);
            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 (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();
    }
}
Private Sub CreateServerDocumentFromPath(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)
            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 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

Poznámky

Pomocí tohoto konstruktoru můžete získat přístup k datům v mezipaměti nebo informacím manifestu nasazení v dokumentu, který je na disku. Při použití tohoto konstruktoru se zadaný dokument otevře s přístupem pro čtení i zápis.

Platí pro

ServerDocument(Byte[], String)

Inicializuje novou instanci ServerDocument třídy pomocí pole bajtů, které představuje dokument, který se má načíst, a příponu názvu souboru dokumentu.

public:
 ServerDocument(cli::array <System::Byte> ^ bytes, System::String ^ fileType);
public ServerDocument (byte[] bytes, string fileType);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : byte[] * string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (bytes As Byte(), fileType As String)

Parametry

bytes
Byte[]

Pole bajtů, které představuje dokument, který se má načíst.

fileType
String

Přípona názvu souboru dokumentu, který je uložený v parametru bytes , před kterým je tečka (.) – například ".xlsx" nebo ".docx".

Výjimky

Parametr bytes je null nebo prázdný.-or-Parametr fileType je nebo je null prázdný nebo se skládá výhradně z prázdných znaků.

Parametr fileType určuje příponu názvu souboru, která není podporována modulem runtime Visual Studio Tools for Office.

Soubor zadaný nástrojem documentPath má vlastní nastavení, které nebylo vytvořeno pomocí sady Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime).

Příklady

Následující příklad kódu používá [ServerDocument – konstruktor (byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.%23ctor%28System.Byte%5B%5D%2CSystem Konstruktor.String%29> pro vytvoření nového konstruktoru [ServerDocument (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument> ) z pole bajtů, které obsahuje excelový sešit s příponou .xlsx názvu souboru. Příklad pak použije vlastnost [ServerDocument Konstruktor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Document%2A> k zobrazení počtu bajtů v dokumentu.

Tento příklad vyžaduje:

  • Projekt konzolové aplikace nebo jiný projekt mimo sadu Office

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

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud projekt cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud je projekt zaměřen na rozhraní .NET Framework 3.5).

  • Imports (pro Visual Basic) nebo using (pro C#) příkazy pro [ServerDocument – konstruktor (Byte<xref:Microsoft.VisualStudio.Tools.Applications?displayProperty=fullName> a [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.Runtime?displayProperty=fullName> namespaces v horní části souboru kódu.

private void CreateServerDocumentFromByteArray(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            // Read the file into a byte array.
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open,
                System.IO.FileAccess.Read);
            byte[] buffer = new byte[(int)stream.Length];
            stream.Read(buffer, 0, (int)buffer.Length);

            // Display the number of bytes in the document.
            serverDocument1 = new ServerDocument(buffer,
                "*.xlsx");
            MessageBox.Show("The Document property contains " +
                serverDocument1.Document.Length.ToString() +
                " bytes.");
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    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();
        if (stream != null)
            stream.Close();
    }
}
Private Sub CreateServerDocumentFromByteArray(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing
    Dim stream As System.IO.FileStream = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            ' Read the file into a byte array.
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open, _
                System.IO.FileAccess.Read)
            Dim buffer(Fix(stream.Length)) As Byte
            stream.Read(buffer, 0, Fix(buffer.Length))

            ' Display the number of bytes in the document.
            serverDocument1 = New ServerDocument(buffer, "*.xlsx")
            MessageBox.Show("The Document property contains " & _
                serverDocument1.Document.Length.ToString() & " bytes.")
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    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
        If Not (stream Is Nothing) Then
            stream.Close()
        End If
    End Try
End Sub

Poznámky

Pomocí tohoto konstruktoru můžete získat přístup k datům uloženým v mezipaměti nebo informacím manifestu nasazení v dokumentu, který je již v paměti. Při použití tohoto konstruktoru se dokument otevře s přístupem pro čtení i zápis.

Parametr fileType se používá pouze k určení typu dokumentu, který je uložen v bajtovém poli. Hodnota fileType je mapována na jeden z typů souborů, které jsou podporovány pro přizpůsobení na úrovni dokumentu. O otevření souboru se nepokusíte. Volitelně můžete předat úplný název souboru (například "Workbook1.xlsx"), ale pokud to uděláte, použije se jenom přípona názvu souboru. Další informace o podporovaných typech souborů najdete v tématu Architektura přizpůsobení Document-Level.

Chcete-li získat přístup k pole bajtů pro dokument po volání tohoto konstruktoru, použijte [ServerDocument – konstruktor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Document%2A> vlastnost.

Platí pro

ServerDocument(Stream, String)

Inicializuje novou instanci ServerDocument třídy pomocí streamu, který představuje dokument, který se má načíst, a příponu názvu souboru dokumentu.

public:
 ServerDocument(System::IO::Stream ^ stream, System::String ^ fileType);
public ServerDocument (System.IO.Stream stream, string fileType);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : System.IO.Stream * string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (stream As Stream, fileType As String)

Parametry

stream
Stream

Datový proud, který představuje dokument, který se má načíst.

fileType
String

Přípona názvu souboru dokumentu, který je uložený v parametru bytes , před kterým je tečka (.) – například ".xlsx" nebo ".docx".

Výjimky

Parametr stream je null nebo prázdný.-or-Parametr fileType je nebo je null prázdný nebo se skládá výhradně z prázdných znaků.

Parametr stream má nulovou délku nebo je jeho aktuální pozice na konci streamu.

Parametr fileType určuje příponu názvu souboru, která není podporována modulem runtime Visual Studio Tools for Office.

Soubor zadaný nástrojem documentPath má vlastní nastavení, které nebylo vytvořeno pomocí sady Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime).

Příklady

Následující příklad kódu používá ServerDocument(Stream, String) konstruktor k vytvoření nového ServerDocument z FileStream excelového sešitu s příponou .xlsx názvu souboru. Kód pak zobrazí adresu URL manifestu nasazení pro přizpůsobení, které je připojené k dokumentu.

Tento příklad vyžaduje:

  • Projekt konzolové aplikace nebo jiný projekt mimo sadu Office

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

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud projekt cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud je projekt zaměřen na rozhraní .NET Framework 3.5).

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

private void CreateServerDocumentFromStream(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open);
            serverDocument1 = new ServerDocument(stream,
                "*.xlsx");
            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 (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();
        if (stream != null)
            stream.Close();
    }
}
Private Sub CreateServerDocumentFromStream(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing
    Dim stream As System.IO.FileStream = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open)
            serverDocument1 = New ServerDocument(stream, "*.xlsx")
            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 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
        If Not (stream Is Nothing) Then
            stream.Close()
        End If
    End Try
End Sub

Poznámky

Pomocí tohoto konstruktoru můžete získat přístup k datům uloženým v mezipaměti nebo informacím manifestu nasazení v dokumentu, který je již v paměti. Při použití tohoto konstruktoru se dokument otevře s přístupem pro čtení i zápis.

Parametr fileType se používá pouze k určení typu dokumentu, který je uložen v bajtovém poli. Hodnota fileType je mapována na jeden z typů souborů, které jsou podporovány pro přizpůsobení na úrovni dokumentu. O otevření souboru se nepokusíte. Volitelně můžete předat úplný název souboru (například "Workbook1.xlsx"), ale pokud to uděláte, použije se jenom přípona názvu souboru. Další informace o podporovaných typech souborů najdete v tématu Architektura přizpůsobení Document-Level.

Pokud chcete získat přístup k poli bajtů pro dokument po volání tohoto konstruktoru Document , použijte vlastnost .

Platí pro

ServerDocument(String, FileAccess)

Inicializuje novou instanci ServerDocument třídy pomocí úplné cesty k dokumentu, který se má načíst, a hodnoty, která označuje přístup k souboru pro dokument.

public:
 ServerDocument(System::String ^ documentPath, System::IO::FileAccess access);
public ServerDocument (string documentPath, System.IO.FileAccess access);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : string * System.IO.FileAccess -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (documentPath As String, access As FileAccess)

Parametry

documentPath
String

Úplná cesta k dokumentu, který se má načíst.

access
FileAccess

Hodnota, která označuje přístup k souboru pro dokument.

Výjimky

Parametr documentPath je nebo je null prázdný nebo se skládá výhradně z prázdných znaků.

Hodnota je access System.IO.FileAccess.Write.

Soubor zadaný nástrojem documentPath neexistuje.

Soubor určený parametrem documentPath nemá vlastní nastavení a hodnota access je System.IO.FileAccess.Read.

Soubor zadaný nástrojem documentPath má vlastní nastavení, které nebylo vytvořeno pomocí sady Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime).

Soubor zadaný nástrojem documentPath má příponu názvu souboru, kterou modul runtime Visual Studio Tools for Office nepodporuje.

Příklady

Následující příklad kódu používá ServerDocument(String, FileAccess) konstruktor k vytvoření nového ServerDocument , který načte zadaný dokument s přístupem jen pro čtení. Kód pak zobrazí adresu URL manifestu nasazení pro přizpůsobení, které je připojené k dokumentu.

Tento příklad vyžaduje:

  • Projekt konzolové aplikace nebo jiný projekt mimo sadu Office

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

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud projekt cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud je projekt zaměřen na rozhraní .NET Framework 3.5).

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

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

Poznámky

Tento konstruktor použijte pro přístup k datům uloženým v mezipaměti nebo informacím manifestu nasazení v dokumentu, který je na disku, pokud chcete dokument otevřít s přístupem jen pro čtení nebo jen pro zápis. Ve výchozím nastavení ostatní ServerDocument konstruktory otevřou dokument s přístupem pro čtení i zápis.

Platí pro