XmlFormView.XmlForm Property
Gets a reference to an XmlForm object represents the current form and provides access to the form's main data source.
Assembly: Microsoft.Office.InfoPath.Server (in Microsoft.Office.InfoPath.Server.dll)
Use the XmlForm property to get a reference to an XmlForm object that represents the form. A limited subset of members of the XmlForm class can be accessed when using the XmlFormView control. For more information about these members, see the Help included with Microsoft Visual Studio Tools for Applications.
Properties (Read Only)
Methods
Important
|
|---|
|
Using members other than this subset will result in the error "Calling this property or method from a hosting page is not supported." |
Using the XmlForm Property
The XmlForm property can only be accessed during one of the following events:
In the following example, a series of textboxes in the Web page are populated with values from the properties that can be used by accessing the XmlForm property. A value from the main data source of the form is used as the value for TextBox10. This routine is called when code in the form calls the NotifyHost method of the XmlForm object available in the Microsoft.Office.InfoPath namespace, in this case from a button in the form.
The following example requires the following three Imports statements:
Imports System.Xml Imports System.Xml.XPath Imports Microsoft.Office.InfoPath.Server.Controls Protected Sub XmlFormView1_NotifyHost(ByVal sender As Object, ByVal e As Microsoft.Office.InfoPath.Server.Controls.NotifyHostEventArgs) Handles XmlFormView1.NotifyHost Dim xNavMain As XPathNavigator Dim xNameSpace As XmlNamespaceManager Try TextBox2.Text = XmlFormView1.XmlForm.[New].ToString() TextBox3.Text = XmlFormView1.XmlForm.ReadOnly.ToString() TextBox4.Text = XmlFormView1.XmlForm.MainDataSource.ReadOnly.ToString() TextBox5.Text = XmlFormView1.XmlForm.ToString() TextBox6.Text = XmlFormView1.XmlForm.XmlLang.ToString() TextBox7.Text = XmlFormView1.XmlForm.Signed.ToString() TextBox8.Text = XmlFormView1.XmlForm.FormState.Count.ToString() TextBox9.Text = XmlFormView1.XmlForm.DataSources.Count.ToString() xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator() xNameSpace = New XmlNamespaceManager(New NameTable()) xNameSpace.AddNamespace("my", XmlFormView1.XmlForm.NamespaceManager._ LookupNamespace("my").ToString()) TextBox10.Text = xNavMain.SelectSingleNode("/my:myFields/my:field2", xNameSpace).ToString() Catch ex As Exception TextBox11.Text = ex.Message.ToString() End Try End Sub
The following example requires the following three using statements:
using System.Xml; using System.Xml.XPath; using Microsoft.Office.InfoPath.Server.Controls; protected void XmlFormView1_NotifyHost(object sender, NotifyHostEventArgs e) { try { TextBox2.Text = XmlFormView1.XmlForm.New.ToString(); TextBox3.Text = XmlFormView1.XmlForm.ReadOnly.ToString(); TextBox4.Text = XmlFormView1.XmlForm.MainDataSource.ReadOnly.ToString(); TextBox5.Text = XmlFormView1.XmlForm.ToString(); TextBox6.Text = XmlFormView1.XmlForm.XmlLang.ToString(); TextBox7.Text = XmlFormView1.XmlForm.Signed.ToString(); TextBox8.Text = XmlFormView1.XmlForm.FormState.Count.ToString(); TextBox9.Text = XmlFormView1.XmlForm.DataSources.Count.ToString(); XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator(); XmlNamespaceManager xNameSpace = new XmlNamespaceManager(new NameTable()); xNameSpace.AddNamespace("my", XmlFormView1.XmlForm.NamespaceManager.LookupNamespace("my").ToString()); TextBox10.Text = xNavMain.SelectSingleNode("/my:myFields/my:field2", xNameSpace).ToString(); } catch (Exception ex) { TextBox11.Text = ex.Message.ToString(); } }
Important