如何以分页方式(一次 10 个)从 SharePoint API 检索数据?
How to retrieve data from SharePoint API in paged manner (10 at a time)?
我检索 SharePoint 列表中所有文件的代码如下
CamlQuery camlQuery = new CamlQuery
{
ViewXml = @"<View Scope='Recursive'>
<Query>
</Query>
</View>",
FolderServerRelativeUrl = myFolder.ServerRelativeUrl
};
ListItemCollection Items = list.GetItems(camlQuery);
这 returns 一个 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
我检索 SharePoint 列表中所有文件的代码如下
CamlQuery camlQuery = new CamlQuery
{
ViewXml = @"<View Scope='Recursive'>
<Query>
</Query>
</View>",
FolderServerRelativeUrl = myFolder.ServerRelativeUrl
};
ListItemCollection Items = list.GetItems(camlQuery);
这 returns 一个 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