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.

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

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

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

NameDescription
System_CAPS_pubmethodServerDocument(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.

System_CAPS_pubmethodServerDocument(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.

System_CAPS_pubmethodServerDocument(String)

Initializes a new instance of the ServerDocument class using the full path of the document to be loaded.

System_CAPS_pubmethodServerDocument(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.

NameDescription
System_CAPS_pubpropertyCachedData

Gets a CachedData object that represents the cached data that is contained in the document.

System_CAPS_pubpropertyDeploymentManifestUrl

Gets or sets the URL of the deployment manifest for the customization that is associated with the document.

System_CAPS_pubpropertyDocument

Gets the byte array of an in-memory document that is loaded into the ServerDocument.

System_CAPS_pubpropertySolutionId

Gets a GUID that the Visual Studio Tools for Office runtime uses to identify the solution.

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticAddCustomization(String, String, Guid, Uri)

Attaches a customization to the specified document by using the specified document, assembly name, solution ID, and deployment manifest.

System_CAPS_pubmethodSystem_CAPS_staticAddCustomization(String, String, Guid, Uri, Boolean, String[])

This API supports the product infrastructure and is not intended to be used directly from your code.

System_CAPS_pubmethodSystem_CAPS_staticAddCustomization(String, Uri)

Attaches a customization to the specified document by using the specified assembly name and deployment manifest.

System_CAPS_pubmethodClose()

Closes the ServerDocument object.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticGetCustomizationVersion(String)

Returns the version of the Visual Studio Tools for Office runtime that was used to create the customization that is associated with the specified document.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticIsCacheEnabled(String)

Gets a value that indicates whether the specified document has a data cache.

System_CAPS_pubmethodSystem_CAPS_staticIsCustomized(String)

Gets a value that indicates whether the specified document has a customization that was created by using the Visual Studio 2010 Tools for Office Runtime.

System_CAPS_pubmethodSystem_CAPS_staticRemoveCustomization(String)

Removes the customization from the document.

System_CAPS_pubmethodSave()

Saves any changes that were made to the document by using the ServerDocument class.

System_CAPS_pubmethodToString()

(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIDisposable.Dispose()

Releases all resources used by the ServerDocument.

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.

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

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.

Return to top
Show: