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.

NameDescription
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.

NameData TypeDescription
AutoHyperlinkBooleanGets or sets a Boolean value that specifies whether text that appears like a hyperlink is automatically formatted as a hyperlink.
DatesInUTCBooleanGets or sets a Boolean value that specifies whether the query returns dates in Coordinated Universal Time (UTC) format.
FolderMicrosoft.SharePoint.SPFolderGets or sets the folder within a document library from which to return items in the query.
IncludeMandatoryColumnsBooleanGets or sets a Boolean value that specifies whether fields that are required for calculated fields are returned in the query.
ListItemCollectionPositionMicrosoft.SharePoint.SPListItemCollectionPositionGets or sets an object that is used to obtain the next set of rows in a paged view of a list.
MeetingInstanceIdInt32Gets or sets the ID that specifies the meeting instance from which to return information in the query.
QueryStringGets or sets the inner XML used in the query.
RecurrenceOrderByBooleanGets 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.
RowLimitUInt32Gets or sets a limit for the number of items returned in the query per page.
ViewAttributesStringGets or sets the attributes of the view used in the query.
ViewFieldsStringGets or sets the fields that are displayed in the query.
ViewXmlStringGets 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

Page view tracker