ServerDocument Constructor (Stream, String)
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Initializes a new instance of the ServerDocument class using a stream that represents the document to be loaded and the file name extension of the document.
Assembly: Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
The stream parameter is Nothing or empty.
The fileType parameter is Nothing or empty or consists entirely of white space characters.
The stream parameter has zero length or its current position is at the stream's end.
The fileType parameter specifies a file name extension that is not supported by the Visual Studio Tools for Office runtime.
The file specified by documentPath has a customization that was not created with the Visual Studio 2010 Tools for Office Runtime or the Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime).
Use this constructor to access the cached data or deployment manifest information in a document that is already in memory. When you use this constructor, the document is opened with read/write access.
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 are 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.xlsx"), 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.
The following code example uses the constructor to create a new ServerDocument from a FileStream that contains an Excel workbook with the .xlsx file name extension. The code then displays the URL of the deployment manifest for the customization that is attached to the document.
This example requires:
A console application project or some other non-Office project.
References to the following assemblies:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.dll (if the project targets the .NET Framework 4 or the .NET Framework 4.5).
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (if the project targets the .NET Framework 3.5).
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
- 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.