ServerDocument Constructor (array<Byte[], String) (2003 System)
Initializes a new instance of the ServerDocument class using a byte array that represents the document to be loaded and the file extension of the document.
Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime
Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in Microsoft.VisualStudio.Tools.Applications.Runtime.dll)
Syntax
'Declaration
Public Sub New ( _
bytes As Byte(), _
fileType As String _
)
'Usage
Dim bytes As Byte()
Dim fileType As String
Dim instance As New ServerDocument(bytes, fileType)
public ServerDocument(
byte[] bytes,
string fileType
)
Parameters
- bytes
Type: array<System.Byte[]
A byte array that represents the document to be loaded.
- fileType
Type: System.String
The file extension of the document that is stored in the bytes parameter, preceded by a period (.)—for example, ".xls" or ".doc".
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The bytes parameter is nulla null reference (Nothing in Visual Basic) or empty. -or- The fileType parameter is nulla null reference (Nothing in Visual Basic) or empty or consists entirely of white space characters. |
CannotLoadManifestException | The file specified by the bytes parameter does not have a Visual Studio Tools for Office customization. |
UnknownCustomizationFileException | The fileType parameter specifies a file name extension that is not supported by Visual Studio Tools for Office. |
Remarks
Use this constructor to access the cached data or application manifest in a document that is already in memory. When you use this constructor, the document is opened with read/write access.
To use this constructor, the document must already have a Visual Studio Tools for Office customization. If you want to open a document that does not yet have a Visual Studio Tools for Office customization, use the ServerDocument.ServerDocument(String, Boolean) or ServerDocument.ServerDocument(String, Boolean, FileAccess) constructor and set the onClient parameter to true. The client computer must have Word or Excel installed to use these constructors.
The fileType parameter is used only to determine the type of document that is stored in the byte array. The value of fileType is mapped to one of the file types that is supported for document-level customizations. No attempt is made to open the file. You can optionally pass in a complete file name (for example, "Workbook1.xls"), but if you do this, only the file name extension is used. For more information about the supported file types, see Architecture of Document-Level Customizations.
To access the byte array for the document after calling this constructor, use the Document property.
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.