Export (0) Print
Expand All

ServerDocument Class

Provides access to the cached data and customization information in a document or workbook that is part of a document-level customization created by using the Office development tools in Visual Studio.

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

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

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

The ServerDocument type exposes the following members.

  NameDescription
Public methodServerDocument(String)Initializes a new instance of the ServerDocument class using the full path of the document to be loaded.
Public methodServerDocument(Byte[], String)Initializes a new instance of the ServerDocument class using a byte array that represents the document to be loaded and the file name extension of the document.
Public methodServerDocument(Stream, String)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.
Public methodServerDocument(String, FileAccess)Initializes a new instance of the ServerDocument class using the full path of the document to be loaded and a value that indicates the file access for the document.
Top

  NameDescription
Public propertyCachedDataGets a CachedData object that represents the cached data that is contained in the document.
Public propertyDeploymentManifestUrlGets or sets the URL of the deployment manifest for the customization that is associated with the document.
Public propertyDocumentGets the byte array of an in-memory document that is loaded into the ServerDocument.
Public propertySolutionIdGets a GUID that the Visual Studio Tools for Office runtime uses to identify the solution.
Top

  NameDescription
Public methodStatic memberAddCustomization(String, Uri)Attaches a customization to the specified document by using the specified assembly name and deployment manifest.
Public methodStatic memberAddCustomization(String, String, Guid, Uri)Attaches a customization to the specified document by using the specified document, assembly name, solution ID, and deployment manifest.
Public methodStatic memberAddCustomization(String, String, Guid, Uri, Boolean, String[])Infrastructure.
Public methodCloseCloses the ServerDocument object.
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberGetCustomizationVersionReturns the version of the Visual Studio Tools for Office runtime that was used to create the customization that is associated with the specified document.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberIsCacheEnabledGets a value that indicates whether the specified document has a data cache.
Public methodStatic memberIsCustomizedGets a value that indicates whether the specified document has a customization that was created by using the Visual Studio 2010 Tools for Office Runtime.
Public methodStatic memberRemoveCustomizationRemoves the customization from the document.
Public methodSaveSaves any changes that were made to the document by using the ServerDocument class.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDisposable.DisposeReleases all resources used by the ServerDocument.
Top

Use the ServerDocument class to manage certain aspects of document-level customizations on a computer that does not have Excel or Word installed. You typically use this class in applications that do not integrate with Office, such as Console projects or Windows Forms projects, rather than Office projects.

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.

There are two different versions of the ServerDocument class in the Visual Studio 2010 Tools for Office Runtime. The version you should use depends on the target .NET Framework of the application in which you want to use the class:

  • For applications that target the .NET Framework 4 or the .NET Framework 4.5, use the Microsoft.VisualStudio.Tools.Applications.ServerDocument class in the Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll assembly.

  • For applications that target the .NET Framework 3.5, use the Microsoft.VisualStudio.Tools.Applications.ServerDocument class in the Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll assembly.

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.

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 customization; otherwise, these constructors will throw a CannotLoadManifestException exception.

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.

The following code example creates a new ServerDocument that loads a specified document and 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).

      or

    • 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).

  • 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();
    }
}

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