Compartir a través de


Document (Propiedad) (2003 System)

Actualización: noviembre 2007

Obtiene la matriz de bytes de un documento almacenado en memoria que se carga en ServerDocument.

Espacio de nombres:  Microsoft.VisualStudio.Tools.Applications.Runtime
Ensamblado:  Microsoft.VisualStudio.Tools.Applications.Runtime (en Microsoft.VisualStudio.Tools.Applications.Runtime.dll)

Sintaxis

'Declaración
Public ReadOnly Property Document As Byte()
'Uso
Dim instance As ServerDocument
Dim value As Byte()

value = instance.Document
public byte[] Document { get; }

Valor de propiedad

Tipo: array<System. . :: .Byte> [] () []

Matriz de bytes de un documento almacenado en memoria que se carga en ServerDocument.

Excepciones

Excepción Condición
DocumentClosedException

El documento se ha cerrado.

Comentarios

Esta propiedad devuelve una matriz de bytes llena si ServerDocument se creó utilizando el constructor ServerDocument(array<Byte>[]()[], String) que tiene un parámetro de matriz de bytes o el constructor ServerDocument(Stream, String) que tiene un parámetro Stream. De lo contrario, esta propiedad devuelve una matriz de bytes vacía.

La utilización de esta propiedad le permite realizar cambios en un documento y enviárselo a un cliente sin escribir el documento en el disco.

Ejemplos

En el ejemplo de código siguiente se utiliza el constructor ServerDocument(array<Byte>[]()[], String) para crear un nuevo ServerDocument. En el ejemplo se utiliza la propiedad Document para mostrar el número de bytes del documento. En este ejemplo se necesita una referencia al ensamblado Microsoft.VisualStudio.Tools.Applications.Runtime y una instrucción Imports (para Visual Basic) o using (para C#) para el espacio de nombres Microsoft.VisualStudio.Tools.Applications.Runtime al principio del archivo de código.

Private Sub DisplayDocumentBytes(ByVal fileName As String)
    If ServerDocument.IsCustomized(fileName) Then
        Dim stream As System.IO.FileStream = Nothing
        Dim serverDocument1 As ServerDocument = Nothing
        Try
            ' Read the file into a byte array.
            stream = New System.IO.FileStream(fileName, _
                System.IO.FileMode.Open, System.IO.FileAccess.Read)
            Dim buffer As Byte() = New Byte(stream.Length) {}
            stream.Read(buffer, 0, buffer.Length)

            ' Create a ServerDocument and display the 
            ' number of bytes in the document.
            serverDocument1 = New ServerDocument(buffer, "*.xls")
            MsgBox("The Document property contains " & _
                serverDocument1.Document.Length.ToString() & " bytes.")
        Finally
            If Not serverDocument1 Is Nothing Then
                serverDocument1.Close()
            End If

            If Not stream Is Nothing Then
                stream.Close()
            End If
        End Try
    Else
        MsgBox("The specified document is not " + _
            "customized.")
    End If
End Sub
private void DisplayDocumentBytes(string fileName)
{
    if (ServerDocument.IsCustomized(fileName))
    {
        ServerDocument serverDocument1 = null;
        System.IO.FileStream stream = null;
        try
        {
            // Read the file into a byte array.
            stream = new System.IO.FileStream(
                fileName, System.IO.FileMode.Open, 
                System.IO.FileAccess.Read);
            byte[] buffer = new byte[(int)stream.Length];
            stream.Read(buffer, 0, (int)buffer.Length);

            // Create a ServerDocument and display the 
            // number of bytes in the document.
            serverDocument1 = new ServerDocument(buffer,
                "*.xls");
            MessageBox.Show("The Document property contains " +
                serverDocument1.Document.Length.ToString() +
                " bytes.");
        }
        finally
        {
            if (serverDocument1 != null)
                serverDocument1.Close();

            if (stream != null)
                stream.Close();
        }
    }
    else
    {
        MessageBox.Show("The specified document is not " +
            "customized.");
    }
}

Permisos

Vea también

Referencia

ServerDocument (Clase)

ServerDocument (Miembros)

Microsoft.VisualStudio.Tools.Applications.Runtime (Espacio de nombres)