ServerDocument.Document Property (2003 System)
Gets the byte array of an in-memory document that is loaded into the ServerDocument.
Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime
Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in Microsoft.VisualStudio.Tools.Applications.Runtime.dll)
Syntax
'Declaration
Public ReadOnly Property Document As Byte()
'Usage
Dim instance As ServerDocument
Dim value As Byte()
value = instance.Document
public byte[] Document { get; }
Property Value
Type: array<System.Byte[]
The byte array of an in-memory document that is loaded into the ServerDocument.
Exceptions
Exception | Condition |
---|---|
DocumentClosedException | The document has been closed. |
Remarks
This property returns a filled byte array if the ServerDocument was created by using the ServerDocument(array<Byte[], String) constructor that has a byte array parameter, or the ServerDocument(Stream, String) constructor that has a Stream parameter. Otherwise, this property returns an empty byte array.
Using this property enables you to make changes to a document and send it to a client without writing the document to disk.
Examples
The following code example uses the ServerDocument(array<Byte[], String) constructor to create a new ServerDocument. The example then uses the Document property to display the number of bytes in the document. This example requires a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime assembly, and an Imports (for Visual Basic) or using (for C#) statement for the Microsoft.VisualStudio.Tools.Applications.Runtime namespace at the top of your code file.
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.");
}
}
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.