如何以分页方式从SharePoint API检索数据(每次10个)



我检索SharePoint列表中所有文件的代码如下

CamlQuery camlQuery = new CamlQuery
{
ViewXml = @"<View Scope='Recursive'>
<Query>
</Query>
</View>",
FolderServerRelativeUrl = myFolder.ServerRelativeUrl
};
ListItemCollection Items = list.GetItems(camlQuery);

这会一次返回sharepoint列表中的所有数据,我只想检索前10项(想实现分页(,我该如何实现?

您可以在caml查询中添加RowLimit,例如:

Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
@"<View Scope='RecursiveAll'>
<RowLimit Page='True' >5000</RowLimit>
</View>";
//Creating a single buffer for storing all the ListItems
List<ListItem> lstListItemCollection = new List<ListItem>();
do
{
ListItemCollection itemCollection = list.GetItems(camlQuery); 
context.Load(itemCollection);

try
{
context.ExecuteQuery();
lstListItemCollection.AddRange(itemCollection);
camlQuery.ListItemCollectionPosition = itemCollection.ListItemCollectionPosition;
}
catch (Exception exec)
{
Console.WriteLine(exec.ToString());
}
}
while (camlQuery.ListItemCollectionPosition != null);

参考:https://www.sptrenches.com/2016/06/get-all-items-in-5000-large-list-with.html

相关内容

  • 没有找到相关文章

最新更新