Compartir a través de


Uso de miembros Microsoft.Office.Interop.InfoPath.SemiTrust no compatibles con InfoPath

Al agregar código a una plantilla de formulario que se creó con el kit de herramientas de Microsoft Office InfoPath 2003 o crear una plantilla de formulario que funcione con el modelo de objetos compatible con InfoPath 2003 (como se describe en Creación de una plantilla de formulario mediante el modelo de objetos de InfoPath 2003), de forma predeterminada, Microsoft InfoPath usará un subconjunto de los objetos y miembros proporcionados por el espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust que son idénticos a los usados por InfoPath 2003. Esto se hace así para ofrecer compatibilidad con InfoPath 2003. Sin embargo, el modelo de objetos proporcionado por el espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust incluye objetos y miembros adicionales que proporcionan una nueva funcionalidad que se agregó a Office InfoPath 2007 e InfoPath.

Por ejemplo, las interfaces PermissionObject y Permission proporcionan una nueva funcionalidad de administración de derechos de información que no está disponible en InfoPath 2003. Esto y otros nuevos objetos agregados al espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust no están disponibles de manera predeterminada cuando abre o crea plantillas de formulario con código administrado con el modelo de objetos compatible con InfoPath 2003.

Del mismo modo, mientras que la interfaz _XDocument2 proporciona la misma funcionalidad que InfoPath 2003; la interfaz _XDocument3 se ha versionado para incluir propiedades y métodos adicionales que se agregaron en Office InfoPath 2007, y el _XDocument4 se ha versionado para incluir propiedades y métodos adicionales que se agregaron en InfoPath.

Si desea usar objetos y miembros agregados en Office InfoPath 2007 o InfoPath en un proyecto de plantilla de formulario creado con el modelo de objetos proporcionado por el espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust , puede hacerlo, pero el código que usa estos miembros no será compatible con InfoPath 2003.

Nota:

Todas las plantillas de formulario con lógica de negocios creadas con el modelo de objetos proporcionado por el espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust, independientemente de si usan objetos y miembros compatibles con InfoPath o no, no se admiten para las plantillas de formulario habilitadas para explorador implementadas en Microsoft SharePoint Server 2010 con InfoPath Forms Services. La lógica de negocios para las plantillas de formulario habilitadas para explorador debe usar el nuevo modelo de objetos de código administrado de InfoPath proporcionado por el espacio de nombres Microsoft.Office.InfoPath .

Ejemplo

Crear un XDocument o una variable de objeto de aplicación para tener acceso a los miembros del nuevo modelo de objetos

Para tener acceso a los nuevos objetos y miembros disponibles en el espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust, debe declarar y convertir variables de objetos en la versión correcta de la interfaz que implementa estos miembros. De forma predeterminada, las thisXDocument variables y thisApplication acceden a las versiones compatibles con InfoPath 2003 de las interfaces de _XDocument2 y _Application2 correspondientes. Para acceder a las interfaces _XDocument3 y _Application3 que proporcionan acceso a la nueva funcionalidad, debe declarar una variable de objeto del tipo _XDocument3 o _Application3 y, a continuación, convertir el objeto devuelto por la thisXDocument variable o thisApplication al mismo tipo que se muestra en los ejemplos siguientes.

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

Acceso a un nuevo objeto desde el XDocument o la variable de objeto de aplicación usando una propiedad de descriptor de acceso

Después de crear una variable de la versión posterior _XDocument3 o el tipo __Application3 , puede usarla para acceder a un objeto o miembro que proporcione una nueva funcionalidad de InfoPath.

En el ejemplo siguiente se muestra cómo usar una variable de objeto de tipo _XDocument3 con la propiedad descriptor de acceso Permission para acceder a la nueva interfaz Permission y a su propiedad Enabled para determinar si la configuración de permisos está habilitada para el formulario.

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

Acceso a un objeto con otra versión y conversión en el tipo de la versión

Si un objeto que existía en el modelo de objetos de InfoPath 2003 tiene ahora nuevas propiedades o métodos agregados, el objeto que los implemente tendrá un nombre que esté en la versión.

Por ejemplo, el objeto ViewInfo no proporciona acceso a dos nuevas propiedades que solo están disponibles cuando se usa el objeto ViewInfo2 con versiones: las propiedades Caption y HideName .

Para tener acceso a estas propiedades, debe declarar una variable de objeto de tipo ViewInfo2 y convertir el objeto devuelto por la propiedad ViewInfos de la variable de objeto _XDocument3 al tipo ViewInfo2 , como se muestra en el ejemplo siguiente.

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