XmlForm.MainDataSource Property (Microsoft.Office.InfoPath)
Gets a DataSource object that represents the main data source of the form.
Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)
Syntax
'Declaration
Public MustOverride ReadOnly Property MainDataSource As DataSource
'Usage
Dim instance As XmlForm
Dim value As DataSource
value = instance.MainDataSource
public abstract DataSource MainDataSource { get; }
Property Value
A DataSource that represents the main data source of the form.
Remarks
The MainDataSource property gets a reference to a DataSource object that represents the underlying XML document of the form. This object can then be used to access the properties and methods of the DataSource class to work with the data in the underlying XML document of the form.
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 from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.
Example
In the following code sample, an event handler for the Loading event first uses the MainDataSource property to call the CreateNavigator method of the DataSource class to create an instance of the System.Xml.XPath.XPathNavigator class positioned at the root node of the underlying XML document of the form. Then, it uses the SelectSingleNode method of the XPathNavigator object to navigate to the employee field (resolving namespace prefixes using the NamespaceManager property) and 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
See Also
Reference
XmlForm Class
XmlForm Members
Microsoft.Office.InfoPath Namespace