次の方法で共有


[方法] InfoPath 2003 と互換性のない Microsoft.Office.Interop.InfoPath.SemiTrust のメンバを使用する方法

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

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

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

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

メモメモ :

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

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

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

// 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 2007 の新機能を提供するオブジェクトやメンバにアクセスできます。

次の例は、_XDocument3 型のオブジェクト変数を Permission アクセサ プロパティと共に使用して、新しい 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())