Partager via


SharePointListRWQueryConnection.Execute Method (XPathNavigator)

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

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustOverride Sub Execute ( _
    output As XPathNavigator _
)
'Usage
Dim instance As SharePointListRWQueryConnection
Dim output As XPathNavigator

instance.Execute(output)
public abstract void Execute(
    XPathNavigator output
)

Parameters

Exceptions

Exception Condition
WebException

The query operation failed.

ArgumentNullException

The parameter passed to this method is a null reference (Nothing in Visual Basic).

ArgumentException

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

Remarks

Setting the output parameter to a null reference (Nothing in Visual Basic) 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 InfoPath Filler or in a Web browser.

Examples

In the following code example, the Execute(XPathNavigator) method of the SharepointListRWQueryConnection 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();
   outputFile.LoadXml(
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><outputRoot></outputRoot>");

   // Create XmlNamespaceManager for XmlDocument object. When
   // creating a more complex document, use the 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 = 
      outputFileNavigator.SelectSingleNode("/outputRoot", 
      outputFileNamespaceManager);

   // Query the SharePoint list defined for the 
   // SharepointListRWQueryConnection and log the results
   // in the XmlDocument created above.
    SharepointListRWQueryConnection queryConnection = 
      (SharepointListRWQueryConnection)(DataConnections["Contacts"]);
    queryConnection.Execute(outputRootNavigator);

   // 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 = 
      mainNavigator.SelectSingleNode("/my:myFields/my:QueryOutput",
      NamespaceManager);
    queryOutputNavigator.SetValue(outputRootNavigator.InnerXml);
}
Public Sub ExecuteOutput_Clicked(ByVal sender As Object , _
   ByVal e As ClickedEventArgs)
{
   ' Create the XmlDocument to accept the query results.
   Dim outputFile As XmlDocument = new XmlDocument()
   outputFile.LoadXml(
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><outputRoot></outputRoot>")

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

   ' Create an XPathNavigator positioned at the root of the
   ' XmlDocument output file created above.
   Dim outputFileNavigator As XPathNavigator = _
      outputFile.CreateNavigator()
   Dim outputRootNavigator As XPathNavigator = 
      outputFileNavigator.SelectSingleNode("/outputRoot", 
      outputFileNamespaceManager)

   ' Query the SharePoint list defined for the 
   ' SharepointListRWQueryConnection and log the results
   '  in the XmlDocument created above.
    Dim myQueryConnection As SharepointListRWQueryConnection  = _
      DirectCast(DataConnections["Contacts"], _
      SharepointListRWQueryConnection)
    myQueryConnection.Execute(outputRootNavigator);

   ' Insert the results of the query from the XmlDocument 
   ' in the QueryOutput field of the main data source of the form.
   Dim mainNavigator As XPathNavigator  = _
      MainDataSource.CreateNavigator()
   Dim queryOutputNavigator As XPathNavigator  = 
      mainNavigator.SelectSingleNode("/my:myFields/my:QueryOutput", _
      NamespaceManager)
    queryOutputNavigator.SetValue(outputRootNavigator.InnerXml)
End Sub

See Also

Reference

SharePointListRWQueryConnection Class

SharePointListRWQueryConnection Members

Execute Overload

Microsoft.Office.InfoPath Namespace