共用方式為


SPQuery class

表示清單檢視中的查詢。

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPQuery

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Class SPQuery
'用途
Dim instance As SPQuery
public class SPQuery

備註

Type屬性會查閱] 及 [使用者欄位特別有用的。否則,如果沒有該屬性,查詢不會傳回預期的結果。在某些情況下,查詢可能會完全失敗。

如需有關如何使用 Language-Integrated 查詢 (LINQ) 查詢來擷取清單項目,在SharePoint Foundation中的資訊,請參閱Managing Data with LINQ to SharePoint

Examples

下列程式碼範例會顯示在 [狀態] 欄位置等於完成的工作] 清單項目標題。這個範例使用共同作業應用程式標記語言 (連同 CAML)來定義查詢。

這個範例要求using指示詞 (在 Visual Basic 的Imports ) 的Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空間。

Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Dim list As SPList = webSite.Lists("Tasks")

Dim query As New SPQuery()
query.Query = "<Where><Eq><FieldRef Name='Status'/>" + _
  "<Value Type='Text'>Completed</Value></Eq></Where>"
Dim items As SPListItemCollection = list.GetItems(query)

Dim item As SPListItem
For Each item In  items
    Response.Write((SPEncode.HtmlEncode(item("Title").ToString()) + _
      "<BR>"))
Next item
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>");
}

Thread safety

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

請參閱

參照

SPQuery members

Microsoft.SharePoint namespace