使用SharePoint 2013中的JSOM / Jqury / REST在文档库中获取文件夹文件 [英] To get the folder files inside Document library using JSOM/Jqury /REST in SharePoint 2013

查看:102
本文介绍了使用SharePoint 2013中的JSOM / Jqury / REST在文档库中获取文件夹文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我有一个文档库和内部文档库,我有年度文件夹,现在我要显示当前年份文件夹文件,我们每年都有文件夹月份文件夹也是。 

I have a document library and inside document library, I have year wise folders, Now I want to display the current year folder files, Each year folder we have month wise folder also. 

我想将所有这些文件显示在一个表中。像展开和折叠一样

I want to display all these files to one table. Like as expand and collapse

例如:文件库: 

Ex: Document Library: 

2019 - 文件夹

2019--Folder

    Jan - 文件夹

    Jan--Folder

        Test.word-Filename

        Test.word—Filename

         Test.PPT-Filename

        Test.PPT—Filename

我想解决方案应该 就像这样,我们需要扩展和崩溃 

I want solution should  be like this, We need to expand and collapse also

year

Word Files

Word Files

PPT

- FY2019

- FY2019

文件名链接

带链接的文件名

   Jan

   Jan

文件名链接

文件名链接

   Feb

   Feb

文件名链接

文件名链接

   Mar

   Mar

文件名链接

文件名链接

推荐答案

嗨Suresh,

Hi Suresh,

您可以使用Rest API getfolderbyserverrelativeurl来获取每个月文件夹文件,假设有一个库,在每个月的文件夹中,以下是供您参考的示例代码:

You could use Rest API getfolderbyserverrelativeurl to get each month folder files, suppose there is a library and in each month folder, here is the sample code for your reference:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">

const d = new Date();
const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
];
var year= d.getFullYear();
monthNames.forEach(function(month) {

    getfiles(year,month);
});
function getfiles(Year,Month)
{
         
        var folderrelativeurl="Shared%20Documents"+"/"+Year+"/"+Month;


.ajax( {
url:_spPageContextInfo.siteAbsoluteUrl +" / _ api / web / getfolderbyserverrelativeurl('" + folderrelativeurl +"')/ Files",
type:" GET",
contentType :" application / json; odata = verbose",
header:{
" Accept":" application / json; odata = verbose",
" X-RequestDigest":
.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('"+folderrelativeurl+"')/Files", type: "GET", contentType: "application/json;odata=verbose", headers: { "Accept": "application/json;odata=verbose", "X-RequestDigest":


(" #__ REQUESTDIGEST")。val()
},
成功:函数(数据){


for(var i = 0; i< data.d.results.length; i ++)
{
console.log(data.d.results [i] .Name);
console.log(data.d.results [i] .ServerRelativeUrl);
}

},
错误:函数(数据){
alert(JSON.stringify(data));
}
});

}
< / script>
("#__REQUESTDIGEST").val() }, success: function (data) { for(var i=0;i<data.d.results.length;i++) { console.log(data.d.results[i].Name); console.log(data.d.results[i].ServerRelativeUrl); } }, error: function (data) { alert(JSON.stringify(data)); } }); } </script>

获取文件名和相对网址后,您可以生成< a href ='relativeurl>文件名< a>然后绑定到一个html数据表:

After getting the file name and relative url, you could generate the <a href='relativeurl>filename<a> and then bind to a html datatable:

使用jQuery和Rest API将SharePoint Online列表数据绑定到HTML表中

谢谢

最好的问候


这篇关于使用SharePoint 2013中的JSOM / Jqury / REST在文档库中获取文件夹文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆