次の方法で共有


ServerDocument.GetCustomizationVersion メソッド

指定されたドキュメントに関連付けられているカスタマイズの作成に使用した Visual Studio Tools for Office Runtime のバージョンを返します。

名前空間:  Microsoft.VisualStudio.Tools.Applications
アセンブリ:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll 内)

構文

'宣言
Public Shared Function GetCustomizationVersion ( _
    documentPath As String _
) As Integer
public static int GetCustomizationVersion(
    string documentPath
)

パラメーター

  • documentPath
    型 : System.String
    確認するドキュメントの完全パスです。

戻り値

型 : System.Int32
関連付けられているカスタマイズの作成に使用した Visual Studio Tools for Office Runtime のバージョンを指定する数値です。

例外

例外 条件
ArgumentNullException

documentPath パラメーターは、nullnull 参照 (Visual Basic では Nothing) または空であるか、または空白文字から構成されます。

FileNotFoundException

documentPath で指定されたファイルが存在しません。

UnknownCustomizationFileException

documentPath で指定されたファイルで、Visual Studio Tools for Office Runtime でサポートされていないファイル名の拡張子が使用されています。

解説

別のバージョンの Visual Studio で作成された Office ソリューションは、Visual Studio Tools for Office Runtime の異なるバージョンを使用します。 各バージョンのランタイムは、そのランタイム バージョンに対応したソリューションで機能するように設計された、それぞれ異なるバージョンの ServerDocument クラスを提供します。 ServerDocument クラスのこのバージョンは Visual Studio 2013、Visual Studio 2010 を使用して、Visual Studio 2008 を使用して作成された Microsoft Office 2007 のソリューションで作成されたソリューションで使用できます。

このメソッドの戻り値の意味を次の表に示します。

戻り値

説明

0

ドキュメントにカスタマイズが含まれていません。

1

Office ドキュメントに対する Visual Studio のツールを使用して作成したカスタマイズ、バージョン 2003 年があります。

2

このドキュメントには、Visual Studio 2005 Tools for Office Second Edition Runtime を使用して作成されたカスタマイズが含まれます。 これが、Visual Studio 2005 Tools for Office および Visual Studio 2008 で Microsoft Office 2003 のカスタマイズに使用されるランタイムのバージョンです。

3

ドキュメントに Office ランタイムの Visual Studio のツールまたは 2010 Microsoft Office System (Version 3.0 Runtime) の Visual Studio のツールを使用して作成したカスタマイズがあります。 ランタイムのバージョン 3.0 は Visual Studio 2008 で 2007 Microsoft Office system 用のカスタマイズで使用されます。

Visual Studio Tools for Office Runtime の別バージョンの詳細については、「Visual Studio Tools for Office Runtime の概要」を参照してください。

次のコード例は、指定のドキュメントを読み込む新しい ServerDocument を作成し、ドキュメントにアタッチされたカスタマイズの配置マニフェストの URL を表示します。 オブジェクトを作成する前に、カスタマイズが Office ランタイムでは、Visual Studio 2010 のツールを使用して作成されたことを確認するために GetCustomizationVersion のメソッドを使用します。

この例には、次の項目が必要です。

  • コンソール アプリケーション プロジェクトまたはその他の Office 以外のプロジェクト。

  • 次のアセンブリへの参照。

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll および Microsoft.VisualStudio.Tools.Applications.Runtime.dll (プロジェクトが .NET Framework 4 または .NET Framework 4.5 を対象とする場合)。

      または

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll および Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (プロジェクトが .NET Framework 3.5 を対象とする場合)。

  • コード ファイルの先頭に、Microsoft.VisualStudio.Tools.Applications 名前空間および Microsoft.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();
    }
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

ServerDocument クラス

Microsoft.VisualStudio.Tools.Applications 名前空間

その他の技術情報

ServerDocument クラスによるサーバー上のドキュメントの管理