Export (0) Print
Expand All

ServerDocument Class (2007 System)

Provides access to the cached data and customization information in a document that is part of a document-level customization for Microsoft Office Excel 2007 or Microsoft Office Word 2007.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class ServerDocument : IDisposable

Use the ServerDocument class to manage certain aspects of document-level customizations on a computer that does not have Excel or Word installed.

Use the following members of the ServerDocument class to perform common tasks:

  • To access and modify data in the data cache of a document on a server, use the CachedData property.

  • To programmatically attach a customization to a document or remove a customization from a document, use the AddCustomization and RemoveCustomization methods.

  • To access or change the URL of the deployment manifest that is associated with the document, use the DeploymentManifestUrl property.

For more information, see Managing Documents on a Server by Using the ServerDocument Class.

Choosing Which Constructor to Use

To use the ServerDocument class to access the cached data or the deployment manifest URL in a document, you must create a ServerDocument object.

There are two sets of ServerDocument constructors:

  • A set that you can use to access a document that has already been opened in memory.

  • A set that you can use to access a document that is on disk.

Accessing a Document in Memory

To access a document that has already been opened in memory, use one of the following constructors:

These constructors accept a byte array or a Stream that represents the document in memory. This is useful if you want to modify the cached data or application manifest in the document before streaming it to a destination by using the HTTP protocol. To use these constructors, the document must already have a Visual Studio Tools for Office customization; otherwise, these constructors will throw a CannotLoadManifestException exception.

Accessing a Document on Disk

To access a document that is on disk, use one of the following constructors:

These constructors accept the full path of the document that you want to open. By default, the document is opened with read/write access. If you want to open the document with read-only or write-only access, use the constructor that has a FileAccess parameter.

Understanding Different Versions of the ServerDocument Class

Visual Studio Tools for Office provides different versions of the ServerDocument class for solutions for Microsoft Office 2003 and the 2007 Microsoft Office system. This version of the ServerDocument class can be used only with solutions that are created by using document-level project templates for Word 2007 and Excel 2007.

To work with a solution that was created by using project templates for Word 2003 and Excel 2003, use the ServerDocument class in the Microsoft.VisualStudio.Tools.Applications.Runtime namespace.

For more information, see Managing Documents on a Server by Using the ServerDocument Class. For a code example that demonstrates how to use both versions of the ServerDocument class in the same code file, see How to: Write Code that Uses Both Versions of the ServerDocument Class.

The following code example creates a new ServerDocument that loads a specified document and then displays the URL of the deployment manifest for the Visual Studio Tools for Office customization that is attached to the document. Before creating the object, the code uses the GetCustomizationVersion method to verify that the customization was created by using the Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime). This is the only runtime that this version of the ServerDocument class is compatible with. For more information, see Managing Documents on a Server by Using the ServerDocument Class.

This example requires a reference to the Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll assemblies, and Imports (for Visual Basic) or using (for C#) statements for Microsoft.VisualStudio.Tools.Applications and Microsoft.VisualStudio.Tools.Applications.Runtime namespaces at the top of your code file.

private void CreateServerDocumentFromPath(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath);
            MessageBox.Show("The URL of the deployment manifest is: \n" +
                serverDocument1.DeploymentManifestUrl.ToString());
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (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 (serverDocument1 != null)
            serverDocument1.Close();
    }
}

System.Object
  Microsoft.VisualStudio.Tools.Applications.ServerDocument

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

Show:
© 2015 Microsoft