Edit

Share via


_XDocument4.Extension Property

Definition

Gets a reference to the global scripting object, which exposes the functions and global variables contained in a Microsoft InfoPath form's primary form code file.

public:
 property System::Object ^ Extension { System::Object ^ get(); };
public object Extension { get; }
member this.Extension : obj
Public ReadOnly Property Extension As Object

Property Value

Returns Object.

Implements

Examples

In the following example, the Extension property is used through the Microsoft.Office.Interop.InfoPath.ObjectWrapper interface to invoke the custom method called MyMethod. This is necessary when using the Extension property in managed code:

ObjectWrapper o = (ObjectWrapper)thisApplication.XDocuments[0].<span class="label">Extension</span>;
 o.GetType().InvokeMember("MyMethod",
 BindingFlags.InvokeMethod |
 BindingFlags.DeclaredOnly | 
 BindingFlags.Public |  
 BindingFlags.Instance, null, o, null);

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

//Custom method added to the project
public string myCustomMethod()
{
return "Method value";
}

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

objXDocument = window.external.XDocument;
myString = objXDocument.<span class="label">Extension</span>.myCustomMethod();

In the following example, the Extension property is used through the Microsoft.Office.Interop.InfoPath.ObjectWrapper interface to invoke the custom method called MyMethod. This is necessary when using the Extension property in managed code:

ObjectWrapper o = (ObjectWrapper)thisApplication.XDocuments[0].<span class="label">Extension</span>;
 o.GetType().InvokeMember("MyMethod",
 BindingFlags.InvokeMethod |
 BindingFlags.DeclaredOnly | 
 BindingFlags.Public |  
 BindingFlags.Instance, null, o, null);

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

//Custom method added to the project
public string myCustomMethod()
{
return "Method value";
}

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

objXDocument = window.external.XDocument;
myString = objXDocument.<span class="label">Extension</span>.myCustomMethod();

Remarks

The Extension object facilitates using the functions and global variables implemented in an InfoPath form's scripting 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 Extension object within a custom task pane, you must first set a reference to the XDocument object by using the Dynamic HTML (DHTML) external property of the DHTML window object, as shown in this example:

objXDocument = window.external.XDocument;

Applies to