XmlForm.Extension property

Gets an Object for accessing the functions and global variables contained in a form's primary form code file using System.Reflection.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property Extension As Object
    Get
'Usage
Dim instance As XmlForm
Dim value As Object

value = instance.Extension
public abstract Object Extension { get; }

Property value

Type: System.Object
An Object for accessing the functions and global variables contained in a form's primary form code file using System.Reflection.

Remarks

The System.Object returned by the Extension property facilitates using the functions and global variables implemented in an InfoPath form code file. Usually, it is used from a custom task pane, from a custom dialog box, or in the XSL Transform (XSLT) of a view where direct access to the functions and variables may be needed.

To use the System.Object within a custom task pane, you must first set a reference to the XmlForm object by using the Dynamic HTML (DHTML) external property of the DHTML window object, as shown in this example.

objXmlForm = window.external.XmlForm;

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

Examples

In the following code example, the Extension property is used to return a System.Object to invoke the custom method called MyMethod.

object extObj = this.Extension;
extObj.GetType().InvokeMember("MyMethod",
   BindingFlags.InvokeMethod |
   BindingFlags.DeclaredOnly |
   BindingFlags.Public |
   BindingFlags.Instance, null, extObj, null);
Dim extObj As Object extObj = Me.Extension
extObj.GetType().InvokeMember("MyMethod", _
   BindingFlags.InvokeMethod Or _
   BindingFlags.DeclaredOnly Or _
   BindingFlags.Public Or _
   BindingFlags.Instance, Nothing, extObj, Nothing)

In the following code example, a method called myCustomMethod of the InfoPath form code project class can be accessed from the custom task pane using the Extension property.

// Custom method added to the form code project.
public string myCustomMethod()
{
   return "Method value";
}
' Custom method added to the form code project.
Function myCustomMethod() As String
   myCustomMethod = "Method value"
End Function

To access myCustomMethod from script in the custom task pane, use the DHTML external property of the DHTML window object.

objXmlForm = window.external.XmlForm;
myString = objXmlForm.Extension.myCustomMethod();
Dim objXmlForm
Dim myString
Set objXmlForm = window.external.XmlForm
myString = objXmlForm.Extension.myCustomMethod()

See also

Reference

XmlForm class

XmlForm members

Microsoft.Office.InfoPath namespace