简体   繁体   English

如何使用 REST API 递归获取 SharePoint 文档库子文件夹、文件夹计数和文件计数?

[英]How to get SharePoint document library sub folders, folders count and files count recursively using REST API?

Assume that I have a Document Library called FileManager in SharePoint.假设我在 SharePoint 中有一个名为FileManager的文档库。 In this file manager, I have multiple subfolders and each of these subfolders has multiple documents.在这个文件管理器中,我有多个子文件夹,每个子文件夹都有多个文档。 Now I wanted to Calculate how many folders and documents are available.现在我想计算有多少文件夹和文档可用。

Ex: Sub Folder A, Sub Folder B, Sub Folder C--> all these 3 subfolders are there under the file manager document library.例如:子文件夹A、子文件夹B、子文件夹C-->所有这3个子文件夹都在文件管理器文档库下。 Now Sub Folders may have many child folders.现在子文件夹可能有很多子文件夹。 Now I want to loop through all these subfolders and its child folders to get the count of folders and files in it using REST API.现在我想遍历所有这些子文件夹及其子文件夹,以使用 REST API 获取其中的文件夹和文件的数量。

Like, Sub Folder A ---> 4 Folders and 100 documents Sub Folder B ---> 10 Folders and 22 Documents例如,子文件夹 A ---> 4 个文件夹和 100 个文档子文件夹 B ---> 10 个文件夹和 22 个文档

this how It should come as a result.结果应该是这样。

How we can achieve this by using the REST API?我们如何通过使用 REST API 来实现这一点?

Please take a reference of below method:请参考以下方法:

Endpoint: Post /_api/Web/lists/getbytitle('Documents')/getitems端点:发布/_api/Web/lists/getbytitle('Documents')/getitems

Body:身体:

{  
      "query" : {
                 "__metadata": { "type": "SP.CamlQuery" }, 
                 "ViewXml" : "<View Scope='RecursiveAll'><ViewFields><FieldRef Name='FileLeafRef' /></ViewFields><Query><Where><And><BeginsWith><FieldRef Name='FileRef' /><Value Type='Lookup'>/sites/sbdev/Shared Documents/Pictures</Value></BeginsWith><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></And></Where></Query></View>"               
       }
}

There are 2 filters:有2个过滤器:

<BeginsWith><FieldRef Name='FileRef' /><Value Type='Lookup'>/sites/sbdev/Shared Documents/Pictures/</Value></BeginsWith>

This filter is used for getting all items whose path starts with '/sites/sbdev/Shared Documents/Pictures/'此过滤器用于获取路径以“/sites/sbdev/Shared Documents/Pictures/”开头的所有项目

<Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq>

And this one is for filtering folder/file这是用于过滤文件夹/文件

I have tested it on my SP online environment, could you please have a try?我已经在我的 SP 在线环境中测试过了,请您试一试好吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "Sharepoint 文档库使用 REST API 获取文件计数" - Sharepoint Document Library get file count using REST API 使用REST Web服务从XML文档获取文件夹和文件 - Using a REST Web Service to get folders and files from XML document 如何使用其余端点获取 Sharepoint 中文件/文件夹/文档的权限级别? - How to get permission levels for Files/Folders/Documents in Sharepoint using rest endpoints? 如何在SharePoint 2013的文件或文件夹REST终结点中包含EffectiveBasePermissions - how to include EffectiveBasePermissions with Files or Folders REST endpoint for SharePoint 2013 如何使用 REST API 作为托管应用程序从客户端上传和获取 SharePoint 文档库中的项目? - How to upload and GET the Items in the SharePoint Document Library from client side using REST API as a HOSTED APP? 文档库中的子文件夹未显示在页面上 - Sub folders in document library not showing up on page REST APi可以在SharePoint文档库中的特定文件夹中获取所有时间 - REST APi to get all times in specific folder in SharePoint document library SharePoint REST API获取可用记录总数 - SharePoint REST API Get total available record count 使用 REST 检索 sharepoint 文档库中子文件夹中的所有文件 - retrieve all files in subfolders in sharepoint document library using REST 使用REST API更改SharePoint文档库上现有文件的文件名 - Change filename of existing file on SharePoint Document library using REST API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM