ServerDocument.GetCustomizationVersion Method

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.

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

public static int GetCustomizationVersion(
	string documentPath
)

Parameters

documentPath
Type: System.String

The full path of the document that you want to check.

Return Value

Type: System.Int32
A number that specifies the version of the Visual Studio Tools for Office runtime that was used to create the associated customization.

ExceptionCondition
ArgumentNullException

The documentPath parameter is null or empty or consists entirely of white space characters.

FileNotFoundException

The file specified by documentPath does not exist.

UnknownCustomizationFileException

The file specified by documentPath has a file name extension that is not supported by the Visual Studio Tools for Office runtime.

Office solutions created in different versions of Visual Studio use different versions of the Visual Studio Tools for Office runtime. Each version of the runtime provides a different version of the ServerDocument class that is designed to work with solutions for that version of the runtime. This version of the ServerDocument class can be used with solutions that are created by using Visual Studio 2013, Visual Studio 2010 and with 2007 Microsoft Office solutions that are created by using Visual Studio 2008.

The following table specifies the meaning of the return values for this method.

Return value

Description

0

The document does not have a customization.

1

The document has a customization that was created by using Visual Studio Tools for Office, Version 2003.

2

The document has a customization that was created by using the Visual Studio 2005 Tools for Office Second Edition runtime. This is the version of the runtime that is used by customizations for Microsoft Office 2003 in Visual Studio 2005 Tools for Office and Visual Studio 2008.

3

The document has a customization that was created by using the Visual Studio 2010 Tools for Office Runtime or the Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime). Version 3.0 of the runtime is used by customizations for the 2007 Microsoft Office system in Visual Studio 2008.

For more information about the different versions of the Visual Studio Tools for Office runtime, see Visual Studio Tools for Office Runtime Overview.

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. Before creating the object, the code uses the GetCustomizationVersion method to verify that the customization was created by using the Visual Studio 2010 Tools for Office Runtime.

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft