Edit

Share via


XmlForm.MainDataSource Property

Definition

Gets a DataSource object that represents the main data source of the form.

public:
 abstract property Microsoft::Office::InfoPath::DataSource ^ MainDataSource { Microsoft::Office::InfoPath::DataSource ^ get(); };
public abstract Microsoft.Office.InfoPath.DataSource MainDataSource { get; }
member this.MainDataSource : Microsoft.Office.InfoPath.DataSource
Public MustOverride ReadOnly Property MainDataSource As DataSource

Property Value

A DataSource that represents the main data source of the form.

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

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.

Applies to