SPQuery Class

The SPQuery class represents a query in a list view.

System.Object

   Microsoft.SharePoint.SPQuery

Public Constructors

The following table shows the public constructors of the SPQuery class and a brief description of each.

Name Description
SPQuery() Initializes a new instance of the SPQuery class.
SPQuery(Microsoft.SharePoint.SPView) Initializes a new instance of the SPQuery class using the specified view.

Public Properties

The following table shows the public properties of the SPQuery class, the data type of each property, and a brief description of each.

Name Data Type Description
AutoHyperlink Boolean Gets or sets a Boolean value that specifies whether text that appears like a hyperlink is automatically formatted as a hyperlink.
DatesInUTC Boolean Gets or sets a Boolean value that specifies whether the query returns dates in Coordinated Universal Time (UTC) format.
Folder Microsoft.SharePoint.SPFolder Gets or sets the folder within a document library from which to return items in the query.
IncludeMandatoryColumns Boolean Gets or sets a Boolean value that specifies whether fields that are required for calculated fields are returned in the query.
ListItemCollectionPosition Microsoft.SharePoint.SPListItemCollectionPosition Gets or sets an object that is used to obtain the next set of rows in a paged view of a list.
MeetingInstanceId Int32 Gets or sets the ID that specifies the meeting instance from which to return information in the query.
Query String Gets or sets the inner XML used in the query.
RecurrenceOrderBy Boolean Gets or sets a Boolean value that specifies whether the sort order used for displaying items in an application that interacts with a SharePoint list remains the same as the sort order used in the browser.
RowLimit UInt32 Gets or sets a limit for the number of items returned in the query per page.
ViewAttributes String Gets or sets the attributes of the view used in the query.
ViewFields String Gets or sets the fields that are displayed in the query.
ViewXml String Gets or sets the XML schema that defines the view.

Thread Safety

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

Remarks

SPQuery can only get the items in the current folder; SPQuery will not get the items in subfolders. This is the design feature in SharePoint Portal Server 2003. To get the items in subfolders, it is necessary to change to the subfolder in SPQuery first. Also it is necessary to specify the format for using dates in the query.

Example

The following code example displays the titles of items in a Tasks list where the Status column equals Completed. The example uses Collaborative Application Markup Language (CAML) to define the query.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint, Microsoft.SharePoint.Utilities, and Microsoft.SharePoint.WebControls namespaces.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security