ServerDocument Constructor (String, FileAccess) (2003 System)
Initializes a new instance of the ServerDocument class using the path of the document to be loaded and a value that indicates the file access for 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 ( _
documentPath As String, _
access As FileAccess _
)
'Usage
Dim documentPath As String
Dim access As FileAccess
Dim instance As New ServerDocument(documentPath, _
access)
public ServerDocument(
string documentPath,
FileAccess access
)
Parameters
- documentPath
Type: System.String
The path of the document to be loaded into the class.
- access
Type: System.IO.FileAccess
One of the FileAccess values.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The documentPath parameter is nulla null reference (Nothing in Visual Basic) or empty or consists entirely of white space characters. |
FileNotFoundException | The file specified by documentPath does not exist. |
IOException | The file specified by documentPath is read-only, or cannot be accessed. |
CannotLoadManifestException | The file specified by the documentPath parameter does not have a Visual Studio Tools for Office customization. |
Remarks
Use this constructor to access the cached data or application manifest in a document that is on disk when you want to specify the file access for the document.
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.
Examples
The following code example uses the ServerDocument(String, FileAccess) constructor to create a new ServerDocument, and then displays the names of all the objects in the specified document's data cache. 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 CreateServerDocumentReadOnly(ByVal fileName As String)
If ServerDocument.IsCustomized(fileName) Then
Dim serverDocument1 As ServerDocument = Nothing
Try
serverDocument1 = New ServerDocument(fileName, _
System.IO.FileAccess.Read)
Dim stringBuilder1 As New System.Text.StringBuilder()
' Display all of the cached data items
' in the document.
Dim hostItem1 As CachedDataHostItem
For Each hostItem1 In serverDocument1.CachedData.HostItems
stringBuilder1.Append(vbLf + "Namespace and class: ")
stringBuilder1.Append(hostItem1.Id + vbLf)
Dim dataItem1 As CachedDataItem
For Each dataItem1 In hostItem1.CachedData
stringBuilder1.Append(" Data item: ")
stringBuilder1.Append(dataItem1.Id + vbLf)
Next dataItem1
Next hostItem1
MsgBox(stringBuilder1.ToString())
Finally
If Not serverDocument1 Is Nothing Then
serverDocument1.Close()
End If
End Try
Else
MsgBox("The specified document is not " + _
"customized.")
End If
End Sub
private void CreateServerDocumentReadOnly(string fileName)
{
if (ServerDocument.IsCustomized(fileName))
{
ServerDocument serverDocument1 = null;
try
{
serverDocument1 = new ServerDocument(fileName,
System.IO.FileAccess.Read);
System.Text.StringBuilder stringBuilder1 =
new System.Text.StringBuilder();
// Display all of the cached data items
// in the document.
foreach (CachedDataHostItem hostItem1 in
serverDocument1.CachedData.HostItems)
{
stringBuilder1.Append("\nNamespace and class: ");
stringBuilder1.Append(hostItem1.Id + "\n");
foreach (CachedDataItem dataItem1 in
hostItem1.CachedData)
{
stringBuilder1.Append(" Data item: ");
stringBuilder1.Append(dataItem1.Id + "\n");
}
}
MessageBox.Show(stringBuilder1.ToString());
}
finally
{
if (serverDocument1 != null)
serverDocument1.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.