【SharePoint】SharePoint Plus Js获取文档库中的所有文件包含子文件夹中的文件

前言

近期有一个获取文档库中所有文件的需求,且文件层级较多,文件数量较大,经过多次尝试,最后用了SharePoint Plus js来实现

 代码

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sharepointplus/browser/sharepointplus.js"></script>
    <script type="text/javascript">
        function getFolderAndFilesInFolder() {
            // if you want to list only the files visible into a folder for a Document Library
            $SP().list("DocName").get({
                fields: "BaseName,FileRef,FSObjType", // "BaseName" is the name of the file/folder; "FileRef" is the full path of the file/folder; "FSObjType" is 0 for a file and 1 for a folder (you need to apply $SP().cleanResult()), "File_x0020_Size" the filesize in bytes
                folderOptions: {
                    path: "folder",
                    show: "FilesAndFolders_InFolder"
                }
            }).then(function (items) {
                for (var i = 0; i < items.length; i++) {
                    console.log(items[i].getAttribute("FileRef"));
                    console.log(items[i].getAttribute("FileLeafRef"));
                    //console.log(items[i].getAttribute("FSObjType"));
                }
            })
        }
    </script>
    <input id="Button1" type="button" onclick="getFolderAndFilesInFolder()" value="button" />

说明:folderOptions.show有四个可选值,如下

1、 "FilesOnly_Recursive" that lists all the files recursively from the provided path (and its children); 获取所有文件包含子文件夹中的文件

2、"FilesAndFolders_Recursive" that lists all the files and folders recursively from the provided path (and its children);获取所有文件夹和文件包含子文件夹中的文件夹和文件

3、"FilesOnly_InFolder" that lists all the files from the provided path;获取指定文件夹中的文件

4、"FilesAndFolders_InFolder" that lists all the files and folders from the provided path获取指定文件夹中的文件夹和文件

分页查询

需要注意的是,如果文件或数据item大于5000条,则需要启用分页查询,因为该接口一次性最多可以返回5000条数据,代码如下

 $SP().list('list name').get({
        fields: "Id,Title",
        rowlimit: 4900,
        paging: true,
        progress: function progress(nbItemsLoaded) {
            // for each new page this function will be called
        }
    }).then(function (data) {

    console.log(data)

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一起来学吧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值