如何获取共享点> 5000的文件

时间:2019-12-15 12:59:25

标签: sharepoint

我有一个共享点位置,文件总数超过5000。在这种情况下,我无法在文件资源管理器中查看它们。是否还有其他选择可以以编程方式检索共享点中可用的文件,而不使用共享点网站

2 个答案:

答案 0 :(得分:0)

您可以为该列编制索引并使用以下代码:

$list = $ctx.Web.Lists.GetByTitle($DocLibName)
$ctx.Load($list)
$ctx.ExecuteQuery()
## View XML
$qCommand = @"
<View Scope="RecursiveAll">
    <Query>
        <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
    </Query>
    <RowLimit Paged="TRUE">5000</RowLimit>
</View>
"@
## Page Position
$position = $null

## All Items
$allItems = @()
Do{
    $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
    $camlQuery.ListItemCollectionPosition = $position
    $camlQuery.ViewXml = $qCommand
 ## Executing the query
    $currentCollection = $list.GetItems($camlQuery)
    $ctx.Load($currentCollection)
    $ctx.ExecuteQuery()

 ## Getting the position of the previous page
    $position = $currentCollection.ListItemCollectionPosition

 # Adding current collection to the allItems collection
    $allItems += $currentCollection
}
# the position of the last page will be Null
Until($position -eq $null) 

此代码类似于分页行为。 $position将上一页索引。

希望这会有所帮助。

答案 1 :(得分:0)

您可以参考本文中的代码: https://sharepoint.stackexchange.com/questions/128373/large-list-issue-with-csom

注意:您必须在骆驼查询中使用索引列。

ClientContext clientContext = new ClientContext("weburl");
List list = clientContext.Web.Lists.GetByTitle("ListTitle");
ListItemCollectionPosition position = null;
do
{
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ListItemCollectionPosition = position;
    camlQuery.ViewXml = @"<View>
                            <ViewFields>
                              <FieldRef Name='Title'/>
                            </ViewFields>
                            <RowLimit>5000</RowLimit>
                          </View>";
    ListItemCollection listItems = list.GetItems(camlQuery);
    clientContext.Load(listItems);
    clientContext.ExecuteQuery();
    position = listItems.ListItemCollectionPosition;
    foreach (ListItem listItem in listItems)
        Console.WriteLine("Title: {0}", listItem["Title"]);
}
while(position != null)