我正在尝试通过一次API调用获取所有文件夹和文件。
我正在使用$expand
/sites/_api/Web/GetFolderByServerRelativeUrl('MyDocuments')?$expand= "Folders/ListItemAllFields,Files/ListItemAllFields,Folders/Files/ListItemAllFields,Folders/Folders/ListItemAllFields,Folders/Folders/Files/ListItemAllFields"
这与预期一样有效。
但随着响应,我得到了一些系统文件夹,如Forms
我试过这种方法https://sharepoint.stackexchange.com/questions/138135/get-all-files-and-folders-in-one-call?noredirect=1&lq=1
所以我在我的请求中添加了$filter
。
/sites/_api/Web/GetFolderByServerRelativeUrl('MyDocuments')?$expand="Folders/ListItemAllFields,Files/ListItemAllFields,Folders/Files/ListItemAllFields,Folders/Folders/ListItemAllFields,Folders/Folders/Files/ListItemAllFields"?$filter="Folder/Name ne 'Attachments' and Folder/Name ne 'Item' and Folder/Name ne 'Forms'"
但看起来过滤器根本不会影响响应。 有什么办法可以在一个请求中使用展开和过滤吗? 如何过滤响应以删除系统文件夹?
答案 0 :(得分:2)
实际上,过滤器表达式是有效的,但在这种情况下会被忽略。
zeek@zeek:~$ oc get all
NAME TYPE FROM LATEST
bc/java Source Git 3
NAME TYPE FROM STATUS STARTED DURATION
builds/java-3 Source Git@85660aa Complete 3 hours ago 55s
NAME DOCKER REPO TAGS UPDATED
is/java 172.30.148.65:5000/zeek/java latest 3 hours ago
NAME REVISION DESIRED CURRENT TRIGGERED BY
dc/java 4 1 1 config,image(java:latest)
dc/mysql 1 1 1 config,image(mysql:5.7)
NAME DESIRED CURRENT READY AGE
rc/java-4 1 1 1 2h
rc/mysql-1 1 1 1 4h
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
routes/java java-zeek.a3c1.starter-us-west-1.openshiftapps.com java 8080-tcp None
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/java 172.30.92.188 <none> 8080/TCP,8443/TCP,8778/TCP 3h
svc/mysql 172.30.217.149 <none> 3306/TCP 4h
NAME READY STATUS RESTARTS AGE
po/java-4-sdkqh 1/1 Running 0 2h
po/mysql-1-23vnw 1/1 Running 0 4h
每个资源集仅支持 /sites/_api/Web/GetFolderByServerRelativeUrl('MyDocuments')?$filter=<expr>
^^^^^^^^^^^^^^
$filter expression could not be applied per item resource
(GetFolderByServerRelativeUrl function returns a Folder resource here)
查询选项。
相反,我建议使用以下ListItemCollection
resource端点:
$filter
返回项目集合(ListItem
resource类型)。使用url: /_api/web/lists/getbytitle('<title>')/items
method: GET
查询选项,所有文件和文件夹都将包含在结果中:
$expand
注意:结果
中不包含系统文件和文件夹
答案 1 :(得分:0)
检查您的REST URL。
在这里你写了:
<强>?$扩大= “文件夹/ ListItemAllFi _____________ ListItemAllFields”?$滤波器= 强>
这里应该是&amp; $ filter 而不是?$ filter
尝试以下网址:
/sites/_api/Web/GetFolderByServerRelativeUrl('MyDocuments')?$expand="Folders/ListItemAllFields,Files/ListItemAllFields,Folders/Files/ListItemAllFields,Folders/Folders/ListItemAllFields,Folders/Folders/Files/ListItemAllFields"&$filter="Folder/Name ne 'Attachments' and Folder/Name ne 'Item' and Folder/Name ne 'Forms'"