XmlForm Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents the underlying XML document of a form.
public ref class XmlForm abstract
public abstract class XmlForm
type XmlForm = class
Public MustInherit Class XmlForm
- Inheritance
-
XmlForm
Remarks
The XmlForm class is a key object in the InfoPath managed code object model that provides properties, methods, and events that can be used to programmatically interact with and manipulate the XML data in the underlying XML document of a form.
While XmlForm objects can be accessed from the XmlFormCollection class using the XmlForms property of the Application class, in most cases, when working with form template business logic you will access the XmlForm class and its members using the this (in C#) or Me (in Visual Basic) keywords without going through the collection.
For example, the following code examples of event handlers for the Loading event use the this or Me keywords to access the MainDataSource and NamespaceManager properties of the XmlForm class. These properties are used to work with an instance of the System.Xml.XPath.XPathNavigatoremployee field (resolving namespace prefixes by using the NamespaceManager property), and then set the field to the current user's username.
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
// Create XPathNavigator positioned at the root of the main data
// source.
XPathNavigator myNav = this.MainDataSource.CreateNavigator()
// Select employee field and set value to username.
myNav.SelectSingleNode("//my:employee",this.NamespaceManager).
SetValue(System.Environment.UserName);
}
Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)
' Create XPathNavigator positioned at the root of the main data
' source.
Dim myNav As XPathNavigator = Me.MainDataSource.CreateNavigator()
' Select employee field and set value to username.
myNav.SelectSingleNode("//my:employee", Me.NamespaceManager). _
SetValue(System.Environment.UserName)
End Sub
Note: It is not necessary to explicitly reference the this or Me keywords to access the members of the XmlForm class in form code. For example, the lines of code to access the MainDataSource property in the previous C# and Visual Basic examples can be written as follows:
XPathNavigator myNav = MainDataSource.CreateNavigator()
Dim myNav As XPathNavigator = MainDataSource.CreateNavigator()
However, using the this or Me keywords when writing code does facilitate IntelliSense statement completion, which lists the members of the XmlForm class when writing business logic code in a form template's FormCode module.
When working with managed code, the source XML data of a form is accessed through the MainDataSource property which returns an instance of the DataSource class that represents the main data source of the form. The CreateNavigator() method of the DataSource class is then used to create an instance of the System.Xml.XPath.XPathNavigator class which is positioned at the root of the form's underlying XML document. The members of the XPathNavigator class can then be used to navigate, read from and write to the form data. For more information about using the XPathNavigator class in InfoPath form code, see How to: Work with System.Xml from Managed-code Form Templates.
The XmlForm class also provides additional properties that can be used to get information about the form and its underlying XML document. It also provides methods that can be used to perform various actions with the form, such as printing, saving, and submitting. Form-level events, such as loading a form, switching views, or a merge operation, are implemented by the FormEvents class. Additionally, events raised by changes to the underlying XML document itself are implemented by the XmlEvents class.
The XmlForm object can be accessed from the XmlFormCollection and Window classes in the InfoPath object model. The following table lists these locations where the XmlForm object is available.
XmlFormCollection | Accessed from the Application object by using the XmlForms property. Provides the Item[Int32] property and Microsoft.Office.InfoPath.XmlFormCollection.Open method for accessing the XmlForm objects that it contains. |
Window | Provides the XmlForm property for accessing the XmlForm object associated with the window. |
In the InfoPath 2003 compatible managed code object model (the types and members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace), which was first introduced in InfoPath 2003 Service Pack 1 in conjunction with the Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET, the following classes provided an XDocument property for accessing the underlying XML document of a form during events: DataDOMEventObject, DocActionEventObject, DocEventObject, DocReturnEventObject, and VersionUpgradeEventObject classes.
In the new InfoPath managed code object model (the types and members of the Microsoft.Office.InfoPath namespace), you use the this (in C#) or Me (in Visual Basic) keywords to access the XmlForm class and its members from event handlers and from other code in your form template business logic.
Constructors
XmlForm() |
Properties
CurrentView |
Gets a View object that represents the current view of the form. |
DataConnections |
Gets a DataConnectionCollection object associated with the form. |
DataSources |
Gets the DataSourceCollection object associated with the form. |
Dirty |
Gets or sets a value that indicates whether the data in a form has been modified since it was last saved. |
Environment |
Gets a Environment object that provides information about which runtime environment (the InfoPath editor, Web browser, or mobile browser) the form is running in. |
Errors |
Gets a reference to the FormErrorCollection that is associated with a form. |
Extension |
Gets an Object for accessing the functions and global variables contained in a form's primary form code file using System.Reflection. |
FormState |
Gets a reference to a property bag of type System.Collections.IDictionary that browser-enabled forms can use to maintain state information across sessions on the server. |
Host |
Gets a System.Object that code running in a hosted instance of InfoPath can use to access the object model of the host application. |
Hosted |
Gets whether InfoPath is hosted as a control in another application. |
HostName |
Gets the name of the application hosting InfoPath as a control. |
MainDataSource |
Gets a DataSource object that represents the main data source of the form. |
NamespaceManager |
Gets a reference to a XmlNamespaceManager object that can be used to resolve, add, or remove namespaces used in the form. |
NetworkState |
Gets a NetworkState object that provides information about the connection state of the client computer or whether a connection can be made to the specified network destination. |
New |
Gets a value that specifies whether a form is new. |
Permission |
Gets a reference to a Permission object associated with the form. |
QueryDataConnection |
Gets a reference to the DataConnection object that represents the data connection that is associated with the form. |
ReadOnly |
Gets a value that indicates whether a form template is read-only or locked. |
Recovered |
Gets a value that indicates whether a form was last saved by an AutoRecover save operation. |
ServerInfo |
Gets a ServerInfo object that provides information about the SharePoint server where the form is located. |
Signed |
Gets a value that indicates whether a form has been digitally signed using digital signatures. |
SignedDataBlocks |
Gets a reference to the SignedDataBlockCollection collection that is associated with a form. |
TaskPanes |
Gets a reference to the TaskPaneCollection that is associated with a form template. |
Template |
Gets a reference to the FormTemplate object that represents the manifest (.xsf) of the form template associated with the form. |
Uri |
Gets the Uniform Resource Identifier (URI) of a form. |
User |
Gets a User object that provides information about the current user of the form. |
UserRole |
Gets or sets the current user of the form's role name. |
ViewInfos |
Gets a reference to the ViewInfoCollection object associated with the form template. |
XmlLang |
Gets or sets the value of the xml:lang attribute in the underlying XML document of the form. |
Methods
Close() |
Closes the form. |
GetWorkflowTasks() |
Gets a reference to a Microsoft.Office.Core.WorkflowTasks collection for the current form. |
GetWorkflowTemplates() |
Gets a reference to a Microsoft.Office.Core.WorkflowTemplates collection for the current form. |
MergeForm(String) |
Merges the current form with the form specified by path or URL. |
MergeForm(XPathNavigator) |
Merges the current form with the target form specified in the node returned by the XPathNavigator passed to the method. |
NotifyHost(String) |
Provides a custom value to the hosting application or ASPX page. |
Print() |
Prints the form content as it is rendered in the form's active view. |
Print(Boolean) |
Prints the form content as it is rendered the form's active view by displaying the Print dialog box. |
Save() |
Saves the form to the Uniform Resource Locator (URL) that it is currently associated with. |
SaveAs(String) |
Saves the form to the specified Uniform Resource Locator (URL). |
SetSaveAsDialogFilename(String) |
Sets the default filename for the SaveAs dialog box. |
SetSaveAsDialogLocation(String) |
Sets the default path for saving the form using the SaveAs dialog box. |
Submit() |
Submits the form using the submit operation defined in the form template. |