Below Code will fetch all the files under MyFolder in Documents library along with extended metadata like document id, modified by, document size and document url etc. ListItemAllFields will do the trick to get all the extended properties of the document.
var folderUrl = "sites/sc1/Documents/MyFolder"
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetFolderByServerRelativeUrl('" + folderUrl + "')/Files?$expand=ModifiedBy,ListItemAllFields",
type: "Get",
cache: false,
async: true,
crossDomain: true,
beforeSend: function(xhr, settings) {
// To do any operation before sending the request
},
xhrFields: {
withCredentials: true
},
dataType: "json",
contentType: "application/json",
success: function(data) {
$.each(data.value, function(index, item) {
var obj = {};
obj["ID"] = item.ListItemAllFields.ID;
obj["Name"] = itemN.ame;
obj["LastUpdatedBy"] = item.ModifiedBy.Title;
obj["LastUpdatedOn"] = item.TimeLastModified;
var fileSize = item.Length / 1024;
obj["Size"] = fileSize.toFixed() + "KB";
});
},
error: function(err) {
console.log("Error Occurred. : " + err);
}
});
var folderUrl = "sites/sc1/Documents/MyFolder"
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetFolderByServerRelativeUrl('" + folderUrl + "')/Files?$expand=ModifiedBy,ListItemAllFields",
type: "Get",
cache: false,
async: true,
crossDomain: true,
beforeSend: function(xhr, settings) {
// To do any operation before sending the request
},
xhrFields: {
withCredentials: true
},
dataType: "json",
contentType: "application/json",
success: function(data) {
$.each(data.value, function(index, item) {
var obj = {};
obj["ID"] = item.ListItemAllFields.ID;
obj["Name"] = itemN.ame;
obj["LastUpdatedBy"] = item.ModifiedBy.Title;
obj["LastUpdatedOn"] = item.TimeLastModified;
var fileSize = item.Length / 1024;
obj["Size"] = fileSize.toFixed() + "KB";
});
},
error: function(err) {
console.log("Error Occurred. : " + err);
}
});
No comments:
Post a Comment