Share via


XmlForm.Extension Property (Microsoft.Office.InfoPath)

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
'Usage
Dim instance As XmlForm
Dim value As Object

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

Property Value

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's code file. Usually, it is used from a custom task pane, from a custom dialog box, or in the XSL Transformation (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.

[JScript]
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 Office InfoPath 2007.

Example

In the following 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 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.

[JScript]
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