InfoPath と互換性のない Microsoft.Office.Interop.InfoPath.SemiTrust メンバーを使用する

Microsoft Office InfoPath 2003 Toolkit で作成されたフォーム テンプレートにコードを追加する場合、または InfoPath 2003 互換オブジェクト モデルで動作する新しいフォーム テンプレートを作成する場合 (「 InfoPath 2003 オブジェクト モデルを使用したフォーム テンプレートの作成」で説明されているように)、既定では、 Microsoft InfoPath では、InfoPath 2003 で使用されるものと同じ Microsoft.Office.Interop.InfoPath.SemiTrust 名前空間によって提供されるオブジェクトとメンバーのサブセットが使用されます。 これは、InfoPath 2003 との互換性を維持するための措置です。 ただし、 Microsoft.Office.Interop.InfoPath.SemiTrust 名前空間によって提供されるオブジェクト モデルには、Office InfoPath 2007 と InfoPath に追加された新機能を提供する追加のオブジェクトとメンバーが含まれています。

たとえば、 PermissionObject インターフェイスと Permission インターフェイスは、InfoPath 2003 では使用できない新しい情報権限管理機能を提供します。 この新機能や、Microsoft.Office.Interop.InfoPath.SemiTrust 名前空間に追加されたその他の新しいオブジェクトは、InfoPath 2003 互換オブジェクト モデルを使用するマネージ コード フォーム テンプレートを開いたり作成したりした場合に既定では使用できません。

同様に、 _XDocument2 インターフェイスは InfoPath 2003 と同じ機能を提供します。 _XDocument3 インターフェイスは、Office InfoPath 2007 で追加されたプロパティとメソッドを含むようにバージョン管理されており、 _XDocument4 は InfoPath に追加された追加のプロパティとメソッドを含むようにバージョン管理されています。

Microsoft.Office.Interop.InfoPath.SemiTrust 名前空間によって提供されるオブジェクト モデルを使用して作成されたフォーム テンプレート プロジェクトで、Office InfoPath 2007 または InfoPath に追加されたオブジェクトとメンバーを使用する場合は、これを行うことができますが、これらのメンバーを使用するコードは InfoPath 2003 と互換性がありません。

注:

InfoPath と互換性のあるオブジェクトとメンバーを使用するかどうかに関係なく、Microsoft.Office.Interop.InfoPath.SemiTrust 名前空間によって提供されるオブジェクト モデルを使用して作成されたビジネス ロジックを含むすべてのフォーム テンプレートは、InfoPath Forms Servicesを使用して Microsoft SharePoint Server 2010 に展開されるブラウザー対応フォーム テンプレートではサポートされていません。 ブラウザー対応フォーム テンプレートのビジネス ロジックでは、 Microsoft.Office.InfoPath 名前空間によって提供される新しい InfoPath マネージ コード オブジェクト モデルを使用する必要があります。

新しいオブジェクト モデルのメンバーにアクセスするための XDocument オブジェクト変数または Application オブジェクト変数を作成する

Microsoft.Office.Interop.InfoPath.SemiTrust 名前空間で使用できる新しいオブジェクトとメンバーにアクセスするには、これらのメンバーを実装するインターフェイスの正しいバージョンにオブジェクト変数を宣言してキャストする必要があります。 既定では、 変数と thisApplication 変数はthisXDocument、対応する_XDocument2インターフェイスと_Application2 インターフェイスの InfoPath 2003 互換バージョンアクセスします。 新しい機能へのアクセスを提供する_XDocument3インターフェイスと_Application3 インターフェイスにアクセスするには、_XDocument3または _Application3 型のオブジェクト変数を宣言し、または thisApplication 変数によってthisXDocument返されるオブジェクトを、次の例に示すように同じ型にキャストする必要があります。

// Declare an object variable of type _XDocument3 and
// cast the object returned by the thisXDocument variable to
// the same type.
_XDocument3 thisXDocument3 = (_XDocument3)thisXDocument;
' Declare an object variable of type _XDocument3 and
' cast the object returned by the thisXDocument variable to
' the same type.
Dim thisXDocument3 As _XDocument3 = _
   DirectCast(thisXDocument, _XDocument3)
// Declare an object variable of type _Application3 and
// cast the object returned by the thisApplication variable to
// the same type.
_Application3 thisApplication3 = (_Application3)thisXDocument;
' Declare an object variable of type _Application3 and
' cast the object returned by the thisXApplication variable to
' the same type.
Dim thisDocument As _XDocument3 = _
   DirectCast(thisXDocument, _XDocument3)

XDocument オブジェクト変数または Application オブジェクト変数からアクセサー プロパティを使用して新しいオブジェクトにアクセスする

新しいバージョン の _XDocument3 または __Application3 型の変数を作成したら、それを使用して、新しい InfoPath 機能を提供するオブジェクトまたはメンバーにアクセスできます。

次の例では、Permission アクセサー プロパティで_XDocument3型のオブジェクト変数を使用して、新しい Permission インターフェイスとその Enabled プロパティにアクセスして、フォームに対してアクセス許可設定が有効になっているかどうかを判断する方法を示します。

// Declare an object variable of type _XDocument3 and
// cast the object returned by the thisXDocument variable to
// the same type.
_XDocument3 thisXDocument3 = (_XDocument3)thisXDocument;
// Use the object variable to access the later version object and
// property.
thisXDocument.UI.Alert(thisDocument3.Permission.Enabled.ToString());
' Declare an object variable of type _XDocument3 and
' cast the object returned by the thisXDocument variable to
' the same type.
Dim thisXDocument3 As _XDocument3 = _
   DirectCast(thisXDocument, _XDocument3)
' Use the object variable to access the later version object and
' property.
thisXDocument.UI.Alert(thisDocument3.Permission.Enabled.ToString())

バージョン付きのオブジェクトにアクセスしてバージョン付きの型にキャストする

InfoPath 2003 オブジェクト モデルに存在していたオブジェクトに新しいプロパティやメソッドが追加された場合、それらの新しいメンバーを実装するオブジェクトにはバージョン付きの名前が付きます。

たとえば、ViewInfo オブジェクトは、バージョン管理された ViewInfo2 オブジェクトを使用する場合にのみ使用できる 2 つの新しいプロパティ ( Caption プロパティと HideName プロパティ) へのアクセスを提供しません。

これらのプロパティにアクセスするには、ViewInfo2 型のオブジェクト変数を宣言し、次の例に示すように、_XDocument3 オブジェクト変数の ViewInfos プロパティによって返されるオブジェクトを ViewInfo2 型にキャストする必要があります。

// Declare an object variable of type _XDocument3 and
// cast the object returned by the thisXDocument variable to
// the same type.
_XDocument3 thisXDocument3 = (_XDocument3)thisXDocument;
// Declare an object variable of type ViewInfo2 and cast the object 
// returned by the ViewInfos property to that type.
ViewInfo2 thisView = (ViewInfo2)thisXDocument3.ViewInfos["View2"];
// Display the value of the new HideName property.
thisXDocument3.UI.Alert(thisView.HideName.ToString());
' Declare an object variable of type _XDocument3 and
' cast the object returned by the thisXDocument variable to
' the same type.
Dim thisXDocument3 As _XDocument3 = _
   DirectCast(thisXDocument, _XDocument3)
' Declare an object variable of type ViewInfo2 and cast the object 
' returned by the ViewInfos property to that type.
Dim thisView As ViewInfo2 = _
   DirectCast(thisXDocument3.ViewInfos("View2"), ViewInfo2)
' Display the value of the new HideName property.
thisXDocument3.UI.Alert(thisView.HideName.ToString())