CalmQuery <rowlimit>无效

时间:2016-03-21 17:03:36

标签: sharepoint-online

我尝试从列表中的文件夹内的文件夹中获取一些文件。为此,我尝试将CalmQueryRowLimit一起使用,因为此文件夹中有很多文件。

但是当我执行代码时,似乎我的行限制不起作用。

$list = $context.Web.Lists.GetByTitle($ListName)
$context.Load($list)

$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'> " +
                "<RowLimit>5000</RowLimit>"+
                "<Query>" +
                    "<OrderBy>"+
                    "<FieldRef Name='FileLeafRef' Ascending='True' />"+
                    "</OrderBy>"+
                    "<Where>" +
                      "<Eq>"+
                        "<FieldRef Name='FileLeafRef' />"+
                        "<Value Type='File'>EDMS API/APICAL Invoice</Value>"+
                      "</Eq>"+
                    "</Where>"+
                "</Query>"+
            "</View>"
$listItems = $list.getItems($query)
$context.Load($listItems)
$context.ExecuteQuery()

1 个答案:

答案 0 :(得分:0)

很可能它不是RowLimit问题,而是Query表达本身。查询:

<Where>
   <Eq>
       <FieldRef Name='FileLeafRef' />
       <Value Type='File'>{value}</Value>
   </Eq>
</Where>

返回名称与{value}匹配的项目,而这些项目不会返回位于{value}中指定的网址的特定文件夹下的文件。

如果您只想包含位于特定文件夹中的文件,您至少可以考虑以下两种方法。

假设以下结构:

News (sub site)
  |
  Documents (library)
      |
      Archive (folder)

然后,以下示例演示了如何在Archive文件夹中包含项目:

1 通过CamlQuery.FolderServerRelativeUrl属性设置文件夹:

$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'> " +
                "<RowLimit>20</RowLimit>"+
                "<Query>" +
                    "<OrderBy>"+
                    "<FieldRef Name='FileLeafRef' Ascending='True' />"+
                    "</OrderBy>"+
                "</Query>"+
            "</View>"
$query.FolderServerRelativeUrl = "/News/Documents/Archive"
$listItems = $list.getItems($query)
$context.Load($listItems)
$context.ExecuteQuery()

2 通过FileDirRef属性设置文件夹

$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'> " +
                "<RowLimit>20</RowLimit>"+
                "<Query>" +
                    "<OrderBy>"+
                    "<FieldRef Name='FileLeafRef' Ascending='True' />"+
                    "</OrderBy>"+
                    "<Where>" +
                      "<Eq>"+
                        "<FieldRef Name='FileDirRef' />"+
                        "<Value Type='File'>/News/Documents/Archive</Value>"+
                      "</Eq>"+
                    "</Where>"+
                "</Query>"+
            "</View>"
$listItems = $list.getItems($query)
$context.Load($listItems)
$context.ExecuteQuery()