Condividi tramite


Procedura: Utilizzare membri di Microsoft.Office.Interop.InfoPath.SemiTrust non compatibili con InfoPath 2003

Quando si aggiunge codice a un modello di modulo creato con Microsoft Office InfoPath 2003 Toolkit o si crea un nuovo modello di modulo supportato dal modello a oggetti compatibile con InfoPath 2003 (come descritto in Procedura: Creare un modello di modulo con codice gestito tramite il modello a oggetti di InfoPath 2003), in Microsoft Office InfoPath 2007 verrà utilizzato per impostazione predefinita un sottoinsieme degli oggetti e dei membri disponibili nello spazio dei nomi Microsoft.Office.Interop.InfoPath.SemiTrust che sono identici a quelli utilizzati in InfoPath 2003. In questo caso, lo scopo è garantire la compatibilità con InfoPath 2003. Il modello a oggetti incluso nello spazio dei nomi Microsoft.Office.Interop.InfoPath.SemiTrust include invece oggetti e membri aggiuntivi che offrono nuove funzionalità aggiunte in InfoPath 2007.

Ad esempio, le interfacce PermissionObject e Permission offrono funzionalità IRM completamente nuove non disponibili in InfoPath 2003. Tali funzionalità e altri oggetti completamente nuovi aggiunti allo spazio dei nomi Microsoft.Office.Interop.InfoPath.SemiTrust non sono disponibili per impostazione predefinita quando si apre o si crea un modello di modulo con codice gestito tramite il modello a oggetti compatibile con InfoPath 2003.

Analogamente, mentre l'interfaccia _XDocument2 offre le stesse funzionalità di InfoPath 2003, la nuova versione dell'interfaccia _XDocument3 include altri metodi e proprietà aggiunti in InfoPath 2007.

È possibile utilizzare oggetti e membri aggiunti a InfoPath 2007 in un progetto modello di modulo creato tramite il modello a oggetti incluso nello spazio dei nomi Microsoft.Office.Interop.InfoPath.SemiTrust, ma il codice in cui vengono utilizzati tali membri non sarà compatibile con InfoPath 2003.

Nota:

Tutti i modelli di modulo con regola business creati tramite il modello a oggetti incluso nello spazio dei nomi Microsoft.Office.Interop.InfoPath.SemiTrust, indipendentemente dal fatto che utilizzino o meno oggetti e membri compatibili con InfoPath 2007, non vengono supportati dai modelli di modulo abilitati per i browser distribuiti in Office Forms Server 2007 o in Microsoft Office SharePoint Server 2007 con InfoPath Forms Services. La regola business dei modelli di modulo abilitati per i browser deve utilizzare il nuovo modello a oggetti con codice gestito di InfoPath incluso nello spazio dei nomi Microsoft.Office.InfoPath.

Esempio

Creazione di una variabile oggetto XDocument o Application per accedere ai membri del nuovo modello a oggetti

Per accedere ai nuovi oggetti e membri disponibili nello spazio dei nomi Microsoft.Office.Interop.InfoPath.SemiTrust, è necessario dichiarare le variabili oggetto ed eseguirne il cast alla versione corretta dell'interfaccia che implementa tali membri. Per impostazione predefinita, le variabili thisXDocument e thisApplication accedono alle versioni compatibili con InfoPath 2003 delle interfacce _XDocument2 e _Application2 corrispondenti. Per accedere alle interfacce _XDocument3 e _Application3 che consentono l'accesso alle nuove funzionalità, è necessario dichiarare una variabile oggetto di tipo _XDocument3 o _Application3 e quindi eseguire il cast dell'oggetto restituito dalla variabile thisXDocument o thisApplication allo stesso tipo, come illustrato negli esempi seguenti.

// 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)

Accesso a un nuovo oggetto dalla variabile oggetto XDocument o Application tramite una proprietà della funzione di accesso

Dopo aver creato una variabile della nuova versione di tipo XDocument3 o _Application3, è possibile utilizzarla per accedere a un oggetto o a un membro che offre le nuove funzionalità di InfoPath 2007.

Nell'esempio seguente viene illustrato l'utilizzo di una variabile oggetto di tipo XDocument3 con la proprietà della funzione di accesso Permission per accedere alla nuova interfaccia Permission e alla relativa proprietà Enabled al fine di determinare se le impostazioni delle autorizzazioni per il modulo sono attivate.

// 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())

Accesso a un oggetto con versione ed esecuzione del cast al tipo di versione

Se un oggetto presente nel modello a oggetti InfoPath 2003 include nuovi metodi o proprietà aggiunti, l'oggetto che implementa i nuovi membri disporrà di un nome con versione.

Ad esempio, l'oggetto ViewInfo non consente l'accesso a due nuove proprietà che sono disponibili solo quando si utilizza l'oggetto con versione ViewInfo2: le proprietà Caption e HideName.

Per accedere a tali proprietà, è necessario dichiarare una variabile oggetto di tipo ViewInfo2 ed eseguire il cast dell'oggetto restituito dalla proprietà ViewInfos della variabile oggetto XDocument3 al tipo ViewInfo2, come illustrato nell'esempio seguente.

// 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())