SharePoint Server 2013'te bir listeyi sorgulamak için SPQuery kullanma

Özgün KB numarası: 2755129

Bu makalede, Microsoft SharePoint Server 2013'te bir listeyi sorgulamak için SPQuery'nin nasıl kullanılacağı açıklanmaktadır.

SharePoint Yönetim Kabuğu'nda SPQuery kullanma

SharePoint Yönetim Kabuğu'nda SPQuery kullanmak için aşağıdaki örnek betike bakın:

$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()

C# uygulamalarında SPQuery kullanma

C# uygulamalarında SPQuery kullanmak için aşağıdaki örnek koda bakın:

  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);
        }
        }

Bilgi türünü tanımlama

Listedeki bir sütundaki bilgilerin bilgi türünü tanımlamak için şu adımları izleyin:

  1. Site koleksiyonu için yönetici kimlik bilgilerini kullanarak SharePoint sitesinde oturum açın.
  2. Görev gibi bir liste açın.
  3. Liste menüsünde Liste Ayarları'na tıklayın.
  4. Sütun bölümünde bilgi türünü görüntüleyin.