如何解决如何以分页方式一次 10 个从 SharePoint API 检索数据?
CamlQuery camlQuery = new CamlQuery
{
ViewXml = @"<View Scope='Recursive'>
<Query>
</Query>
</View>",FolderServerRelativeUrl = myFolder.ServerRelativeUrl
};
ListItemCollection Items = list.GetItems(camlQuery);
这会一次性返回共享点列表中的所有数据,我只想检索前 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。