Sdílet prostřednictvím


ServerDocument.Document – vlastnost

Získá bajtové pole z dokumentu v paměti, který je načten do ServerDocument.

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

Syntaxe

'Deklarace
Public ReadOnly Property Document As Byte()
public byte[] Document { get; }

Hodnota vlastnosti

Typ: array<System.Byte[]
Bajtové pole z dokumentu v paměti, který je načten do ServerDocument.

Výjimky

Výjimka Podmínka
DocumentClosedException

Dokument byl uzavřen.

Poznámky

Tato vlastnost vrátí vyplněné bajtové pole, pokud ServerDocument byl vytvořen pomocí ServerDocument(array<Byte[], String) konstruktor, který má parametr array bajt, nebo ServerDocument(Stream, String) konstruktor, který má Stream parametr.Jinak tato vlastnost vrátí prázdný byte pole.

Pomocí této vlastnosti můžete v dokumentu provést změny a poslat klientovi bez psaní dokumentu na disk.

Příklady

Následující příklad kódu používá ServerDocument(array<Byte[], String) konstruktor pro vytvoření nového ServerDocument z bajtové pole, která obsahuje sešit aplikace Excel s příponou názvu souboru XLSX.V příkladu se pak používá Document vlastnost zobrazit počet bajtů v dokumentu.

Tento příklad vyžaduje:

  • Projekt aplikace konzoly nebo jiného projektu mimo sadu Office.

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

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (Pokud projekt cílen .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 cílen na rozhraní.NET Framework 3.5).

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

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

Zabezpečení rozhraní .NET Framework

Viz také

Referenční dokumentace

ServerDocument Třída

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