Konten ini tidak tersedia dalam bahasa Anda dan berikut adalah versi bahasa Inggris.

SharePointListRWQueryConnection class

Office 2013 and later

Represents a data connection for retrieving data from a SharePoint list or document library.


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

public abstract class SharePointListRWQueryConnection : DataConnection

The SharePointListRWQueryConnection class represents a secondary data connection created in InfoPath that specifies all the information necessary for retrieving data from a SharePoint list or document library. To create a form template that contains a secondary data connection to a SharePoint list or document library, use the Data Connections command on the Data tab.


Code written with the members of the SharePointListRWQueryConnection class is not compatible with a data connection to a SharePoint list or document library created in InfoPath 2003 or InfoPath 2007, with a data connection in a new form template created in InfoPath with one of the InfoPath 2007 Form Templates, or with a data connection converted with the Convert to Previous Version button in the Data Connections dialog box. If you do not need to maintain compatibility with an earlier version of InfoPath and want to write code with members of the SharePointListRWQueryConnection class, convert the data connection with the Convert to Current Version button in the Data Connections dialog box.


You can create a primary (main) data connection to a SharePoint list by creating a new form template with the SharePoint List template. However, it is not possible to write form code behind such a form, because only declarative logic, such as rules, is supported in a form template created with the SharePoint List template. For this reason, you cannot use the SharePointListRWQueryConnection class and its members to work with a primary data connection to a SharePoint list.

The SharePointListRWQueryConnection class provides properties that can be used to get the name of the data connection and the URL of the list or document library on the SharePoint Foundation or Microsoft SharePoint Server site from which the connection retrieves data.

The SharePointListRWQueryConnection object associated with the data connection is accessible by using the DataConnections property of the XmlForm class to return the connection from the DataConnectionCollection of the form template.

The default Execute method, inherited from the DataConnection base class, performs a query or submit operation using the values that were declaratively defined in the InfoPath form template at design time. Additionally, the SharePointListRWQueryConnection class provides the Execute(XPathNavigator) method, which enables you to specify a different location to insert the data that is returned.

In the following code example, a data connection named "Contacts", which connects to a list of contact information on a SharePoint site, is accessed by using the following two-step process. The name "Contacts" is passed to the Item property of the DataConnectionCollection class to retrieve an object that represents the data connection. Then, the object returned from the collection is cast to the SharePointListRWQueryConnection type.

SharePointListRWQueryConnection spConnection = (SharePointListRWQueryConnection)this.DataConnections["Contacts"];

After the reference to the data connection has been set, you can use the properties or methods of the SharePointListRWQueryConnection object. The following code example sets a string variable to the value returned by the Name property inherited from the DataConnection base class.

string spName = spConnection.Name;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.