[英]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.