SPQuery Class
Windows SharePoint Services 3
Represents a query in a list view.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
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 Microsoft Visual Basic) for the ( Default Namespace )Microsoft.SharePoint and ( Default Namespace )Microsoft.SharePoint.Utilities namespaces.
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb) { SPList oList = oWebsiteRoot.Lists["Tasks"]; SPQuery oQuery = new SPQuery(); oQuery.Query = "<Where><Eq><FieldRef Name='Status'/>" + "<Value Type='Text'>Completed</Value></Eq></Where>"; SPListItemCollection collListItems = oList.GetItems(oQuery); foreach (SPListItem oListItem in collListItems) { Response.Write(SPEncode.HtmlEncode(oListItem["Title"].ToString()) + "<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 Best Practices: Using Disposable Windows SharePoint Services Objects. |
Note: