摘要

本文說明如何使用 SPQuery 來查詢 Microsoft SharePoint 伺服器 2013年中的清單。

其他相關資訊

若要使用 SharePoint 管理命令介面中的 SPQuery,請參閱下列的範例指令碼:

$web=Get-SPWeb http://sps15/sites/SiteName #This URL is the URL of Your SharePoint Site$list=$web.Lists["Task"] #"Task" is the name of the list.$query=New-Object Microsoft.SharePoint.SPQuery$query.Query = "<where><eq><FieldRef Name='status'/><value Type='CHOICE'>Not Started</value></eq></where>"# 'Status'is the name of the List Column. 'CHOICE'is the information type of the Column.$SPListItemCollection = $list.GetItems($query)$SPListItemCollection.Count$SPListItemCollection | select Web, DisplayName$web.Dispose()$list=$web.Lists["Task"] $query=New-Object Microsoft.SharePoint.SPQuery$query.Query="<Where><Eq><FieldRef Name='Age'/><Value Type='Number'>400</Value></Eq></Where>" $SPListItemCollection = $list.GetItems($query)$SPListItemCollection.Count$SPListItemCollection | select Web, DisplayName$web.Dispose()

若要使用 SPQuery,C# 應用程式中,請參閱下列的範例程式碼:

  static void Main(string[] args)        {                    SPSite cursite=new SPSite("http://sps15/sites/new");//This URL is the URL of your SharePoint Site.        SPWeb curweb = cursite.OpenWeb();        SPQuery curQry = new SPQuery();        curQry.Query = "<where><eq><FieldRef name='status'/><value type='CHOICE'>Not Started</value></ep></where>";        SPList mylist = curweb.Lists["Task"];//Task is the name for the list.          SPListItemCollection curitems = mylist.GetItems(curQry);          foreach (SPListItem curitem in curitems)          {              string resultitem = curitem["Title"].ToString();              Console.Write(resultitem+"\n\r");          }        if (curweb != null)        {            string title = curweb.Title;            Console.Write(title);        }                                }

若要識別資訊的類型清單中的資料行中的資訊,請依照下列步驟執行:

  1. 使用網站集合系統管理員認證登入到 SharePoint 網站。

  2. 開啟 [工作清單]。

  3. 在 [清單] 功能表上按一下 [清單設定]。

  4. 在 [] 區段中檢視的資訊類型。

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Insiders

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?

Thank you for your feedback!

×