ServerDocument Constructor (String, Boolean, FileAccess) (2003 System)

Initializes a new instance of the ServerDocument class using the path of the document to be loaded, a value that indicates whether to create a Runtime Storage Control if the document does not have a Visual Studio Tools for Office customization, 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, _
    onClient As Boolean, _
    access As FileAccess _
)
'Usage
Dim documentPath As String
Dim onClient As Boolean
Dim access As FileAccess

Dim instance As New ServerDocument(documentPath, _
    onClient, access)
public ServerDocument(
    string documentPath,
    bool onClient,
    FileAccess access
)

Parameters

  • documentPath
    Type: System.String
    The path of the document to be loaded into the class.
  • onClient
    Type: System.Boolean
    true to create a Runtime Storage Control in the document if the document does not have a Visual Studio Tools for Office customization; otherwise, false.

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 the documentPath parameter does not exist.

IOException

The file specified by documentPath is read-only, or cannot be accessed.

CannotLoadManifestException

The file specified by documentPath does not have a Visual Studio Tools for Office customization and the access parameter is Read.

-or-

The file specified by documentPath does not have a Visual Studio Tools for Office customization and onClient is false.

Remarks

Use this constructor if you want to open a document that does not yet have a Visual Studio Tools for Office customization. This is useful if you want to add cached data to a document that does not yet have a customization. When you use this constructor, the document is opened from disk with the specified file access.

If the specified document does not have a Visual Studio Tools for Office customization, this constructor adds a Runtime Storage Control to the document if the onClient parameter is true and the access parameter is ReadWrite. This process requires that the document be on a computer that has Word or Excel installed.

If the document is on a server, you should set onClient to false or use the ServerDocument.ServerDocument(String) or ServerDocument.ServerDocument(String, FileAccess) constructors. For more information about the Runtime Storage Control, see Runtime Storage Control Overview.

Examples

The following code example uses the ServerDocument(String, Boolean, 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 CreateServerDocumentOnClientReadOnly(ByVal fileName As String)
    If ServerDocument.IsCustomized(fileName) Then
        Dim serverDocument1 As ServerDocument = Nothing
        Try
            serverDocument1 = New ServerDocument(fileName, _
                True, System.IO.FileAccess.ReadWrite)
            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 CreateServerDocumentOnClientReadOnly(string fileName)
{
    if (ServerDocument.IsCustomized(fileName))
    {
        ServerDocument serverDocument1 = null;
        try
        {
            serverDocument1 = new ServerDocument(fileName,
                true, System.IO.FileAccess.ReadWrite);
            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

See Also

Reference

ServerDocument Class

ServerDocument Members

ServerDocument Overload

Microsoft.VisualStudio.Tools.Applications.Runtime Namespace