SPQuery.Query Property
Gets or sets the inner XML used in the query.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Property Value
Type: System.StringA string that contains a fragment in Collaborative Application Markup Language that defines the query. The string corresponds to the inner XML of the Query element in CAML, excluding the opening and closing <Query></Query> tags.
The following code example uses the Query property to define a query that returns items whose Field2 values are greater than 1000.
Note
|
|---|
|
For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint. |
This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb) { SPList oList = oWebsiteRoot.Lists["List_Name"]; SPQuery oQuery = new SPQuery(); oQuery.ViewFields = "<FieldRef Name='Field1'/>" + "<FieldRef Name='Field2'/>"; oQuery.Query = "<Where><Geq><FieldRef Name='Field2'/>" + "<Value Type='Number'>1000</Value></Geq></Where>"; SPListItemCollection collListItems = oList.GetItems(oQuery); foreach (SPListItem oListItem in collListItems) { Response.Write(SPEncode.HtmlEncode(oListItem.Xml) + "<BR>"); } }
Note |
|---|
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects. |
Caution
Note