We recommend using Visual Studio 2017

SharepointListQueryConnection.Execute Method (XPathNavigator) (Microsoft.Office.InfoPath)

Overrides the default Execute method to allow specifying a different location to insert the data that is returned.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

public abstract void Execute (
	XPathNavigator output



An XPathNavigator that specifies an XML node in the primary or a secondary data source of the form into which to insert the returned data. The XPathNavigator passed as the output parameter can also specify to insert the data into any XML file on the local computer, or into a System.Xml.XmlDocument held in memory.

Exception typeCondition


The query operation failed or returned no data (the queried list is empty).


The parameter passed to this method is null.


The parameter passed to this method is not valid. For example, it is of the wrong type or format.

Setting the output parameter to null has the same effect as using the default Execute method to return data using the declarative settings defined in the form template.

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.

In the following example, the Execute(output) method of the SharepointListQueryConnection class is used to execute a query against the "Contacts" connection and store the output in an XmlDocument that is created in memory. It then displays the output stored in the XmlDocument in the QueryOutput field of the form.

public void ExecuteOutput_Clicked(object sender, ClickedEventArgs e)
   // Create the XmlDocument to accept the query results.
   XmlDocument outputFile = new XmlDocument();
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><outputRoot></outputRoot>");

   // Create XmlNamespaceManager for XmlDocument object. When
   // creating a more complex document, use AddNamespace method
   // to add a mapping from namespace prefix to namespace URL for 
   // each namespace to this object.
   XmlNamespaceManager outputFileNamespaceManager = 
      new XmlNamespaceManager(outputFile.NameTable);

   // Create an XPathNavigator positioned at the root of the
   // XmlDocument output file created above.
   XPathNavigator outputFileNavigator = outputFile.CreateNavigator();
   XPathNavigator outputRootNavigator = 

   // Query the SharePoint list defined for the 
   // SharepointListQueryConnection and log the results
   // in the XmlDocument created above.
    SharepointListQueryConnection queryConnection = 

   // Insert the results of the query from the XmlDocument in the 
   // QueryOutput field of the main data source of the form.
   XPathNavigator mainNavigator = MainDataSource.CreateNavigator();
   XPathNavigator queryOutputNavigator =