XmlForm.MainDataSource property

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

value = instance.MainDataSource
public abstract DataSource MainDataSource { get; }

Property value

Type: Microsoft.Office.InfoPath.DataSource
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 InfoPath Filler or in a Web browser.

Examples

In the following code example, 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