2013-12-23 51 views
2

尋呼在這裏不起作用,它說錯誤:不支持查詢表達式。 此行發生錯誤:
clientContext.Load(listItems,itms => itms.Skip((PageNumber - 1)* PageSize).Take(PageSize));尋呼問題SP 2010與C#

有人可能會提醒嗎?

感謝

/// <summary> 
    /// Method to return list of documents of a specific document library 
    /// </summary> 
    /// <param name="docLibaryName"></param> 
    /// <returns></returns> 
    public List<Document> GetDocumentsByLibraryName(string spURL, string docLibaryName, int PageSize, int PageNumber) 
    { 

     List<Document> docList = new List<Document>(); 
     //Access the Document Library 
     ClientContext clientContext = new ClientContext(spURL); 
     List sharedDocumentsList = clientContext.Web.Lists.GetByTitle(docLibaryName); 

     //Specify the Caml Query 
     CamlQuery camlQuery = new CamlQuery(); 
     camlQuery.ViewXml = 
      @"<View Scope='Recursive'></View>"; 
     ListItemCollection listItems = sharedDocumentsList.GetItems(camlQuery); 
     clientContext.Load(listItems, itms => itms.Skip((PageNumber - 1) * PageSize).Take(PageSize)); 
     clientContext.ExecuteQuery(); 
     AddItemsToDocumentCollection(docList, listItems); 
     return docList.ToList(); 
    } 

回答

2

Skip運營商不支持,因爲錯誤指示。

CAML中沒有Skip運算符,因此查詢提供程序無法爲您翻譯該查詢。

Sharepoint支持的唯一分頁操作是獲取下一頁,而不是第n頁。在查詢執行後,您可以通過將CamlQuery對象的ListItemCollectionPosition設置爲ListItemCollectionListItemCollectionPosition值來獲取下一頁。如果它爲空,那麼沒有下一頁。您還需要在查詢的viewXML中設置RowLimit以確定頁面大小。

它會是這個樣子:

using (var context = new ClientContext("http://vddp23q-5d16d1e/")) 
{ 
    var query = new CamlQuery(); 
    var list = context.Web.Lists.GetByTitle("Documents"); 
    int pageSize = 10; 
    query.ViewXml = string.Format(
@"<View><RowLimit Paged='true'>{0}</RowLimit></View>", pageSize); 

    ListItemCollection items; 
    do 
    { 
     items = list.GetItems(query); 
     context.Load(items); 
     context.ExecuteQuery(); 
     foreach (var item in items) 
      DoStuff(item); 
     query.ListItemCollectionPosition = items.ListItemCollectionPosition; 
    } 
    while (items.ListItemCollectionPosition != null); 
} 

附註:確保你處置您ClientContext對象。

+0

如何使用這種方法可以實現尋呼?我需要看看其他一些方法嗎? –

+0

@HariGillala請參閱編輯。 – Servy

+0

如果它爲空,那麼沒有下一頁。謝謝,這是一個很好的提示,因爲在頁面結束後返回是不可能的。至少它似乎是。 –