回答

0

使用JSOM或CSOM,你需要指定 'FileDirRef' 在CAML查詢性能,並添加 'RecursiveAll' 範圍:

var camlQuery = new SP.CamlQuery(); 
camlQuery.set_viewXml(
    '<View Scope="RecursiveAll"> " + 
     "<Query>" + 
      "<Where>" + 
       "<Eq>" + 
        "<FieldRef Name="FileDirRef" />" + 
        "<Value Type=\"Text\">yourFolderPath</Value>" + 
       "</Eq>" + 
      "</Where>" + 
     "</Query>" + 
    "</View>'); 
0
function GetFolders() { 
var oWeb = _spPageContextInfo.webAbsoluteUrl; 
var URLC = oWeb + "/_api/web/lists/getByTitle('ListName')/items"; 
$.ajax({ 
    url: URLC, 
    method: "GET", 
    headers: { "Accept": "application/json; odata=verbose" }, 
    async: false, 
    cache: false, 
    success: function (data) { 
     $.each(data.d.results, function (index, item) { 
      $.ajax({ 
       url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('ListName/ListFolder)/listitemallfields/", 
       method: "GET", 
       headers: { "Accept": "application/json; odata=verbose" }, 
       async: false, 
       cache: false, 
       success: function (data) { 
       } 
      });    
     }) 
    }, 
    error: function (data) { } 
}); 

}

0

您可以使用REST API來讀取使用getfolderbyserverrelativeurl列出特定文件夾中的項目。

請參考下代碼:

var folderRelativeUrl = "Relative_URL_Of_Your_Folder"; //here specify relative URL of your folder (e.g. '/Shared Documents') 


getItemFromFolder().then(getItemFromFolderSuccess, getItemFromFolderFailed); 


function getItemFromFolder(){ 
    return $.ajax({ 
     url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('" + folderRelativeUrl + "')/files?$expand=ListItemAllFields", 
     type: "GET", 
     headers: { 
      "Accept": "application/json;odata=verbose" 
     } 
    }); 
} 

function getItemFromFolderSuccess(data){ 
    // success handler 
    var response = data.d.results; // This is Response Object from Server 
} 

function getItemFromFolderFailed(error){ 
    // error handler code 
}