ServerDocument.GetCustomizationVersion 方法 (2007 system)

更新:2007 年 11 月

返回用于创建与指定文档相关联的自定义项的 Visual Studio Tools for Office 运行时的版本。

命名空间:  Microsoft.VisualStudio.Tools.Applications
程序集:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0(在 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 中)

语法

声明
Public Shared Function GetCustomizationVersion ( _
    documentPath As String _
) As Integer
用法
Dim documentPath As String
Dim returnValue As Integer

returnValue = ServerDocument.GetCustomizationVersion(documentPath)
public static int GetCustomizationVersion(
    string documentPath
)

参数

  • documentPath
    类型:System.String

    要检查的文档的完整路径。

返回值

类型:System.Int32

一个编号,指定用于创建关联的自定义项的 Visual Studio Tools for Office 运行时的版本。

异常

异常 条件
ArgumentNullException

documentPath 参数为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者完全由空白字符组成。

FileNotFoundException

documentPath 指定的文件不存在。

UnknownCustomizationFileException

Visual Studio Tools for Office 不支持 documentPath 指定的文件的文件扩展名。

备注

Microsoft Office 2003 和 2007 Microsoft Office system 的 Visual Studio Tools for Office 解决方案使用不同版本的 Visual Studio Tools for Office 运行时。每种版本的运行时提供不同版本的 ServerDocument 类,设计用于该版本运行时的解决方案。此版本的 ServerDocument 类只能用于使用 Word 2007 和 Excel 2007 的文档级项目模板创建的解决方案。

下表说明此方法的返回值的含义。

返回值

说明

0

该文档不具有 Visual Studio Tools for Office 自定义项。

1

该文档具有使用 Visual Studio Tools for Office 2003 版 创建的自定义项。

2

该文档具有使用 Visual Studio 2005 Tools for Office Second Edition 运行时创建的自定义项。这是用于创建 Microsoft Office 2003 的自定义项的运行时版本。

3

该文档具有使用 Microsoft Visual Studio Tools for the Microsoft Office system(3.0 版运行时) 创建的自定义项。这是用于创建 2007 Microsoft Office system 的自定义项的运行时版本。

有关不同版本的 ServerDocument 类的更多信息,请参见使用 ServerDocument 类管理服务器上的文档。有关演示如何将这种方法应用于同一个代码文件中的不同版本的 ServerDocument 类,请参见如何:编写使用两个版本的 ServerDocument 类的代码

有关不同版本的 Visual Studio Tools for Office 运行时的更多信息,请参见 Visual Studio Tools for Office 运行库概述

示例

下面的代码示例创建一个新的 ServerDocument,该文档加载指定的文档,然后显示附加到文档的 Visual Studio Tools for Office 自定义项的部署清单的 URL。在创建对象之前,此代码使用 GetCustomizationVersion 方法验证该自定义项是否使用 Microsoft Visual Studio Tools for the Microsoft Office system(3.0 版运行时) 创建。这是此版本的 ServerDocument 类所兼容的唯一运行时。

此示例需要在代码文件顶部使用对 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 和 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll 程序集的引用,并对 Microsoft.VisualStudio.Tools.ApplicationsMicrosoft.VisualStudio.Tools.Applications.Runtime 命名空间使用 Imports(对于 Visual Basic)或 using(对于 C#)语句。

Private Sub CreateServerDocumentFromPath(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            serverDocument1 = New ServerDocument(documentPath)
            MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                serverDocument1.DeploymentManifestUrl.ToString())
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As 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 Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
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();
    }
}

权限

另请参见

参考

ServerDocument 类

ServerDocument 成员

Microsoft.VisualStudio.Tools.Applications 命名空间

其他资源

使用 ServerDocument 类管理服务器上的文档

如何:编写使用两个版本的 ServerDocument 类的代码