Get AppWeb Resource Information using REST API

Write following code in your App.js file:

(function () {
"use strict";

jQuery(function () {
var call = jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/RootFolder/Folders?$expand=Files", // this expand the file collection
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
call.done(function (data, textStatus, jqXHR) {
var message = jQuery("#message");
message.text("");
jQuery.each(data.d.results, function (index, value) {
//here i don't wanna process empty folders Here value is the folder
if (value.Files.results.length > 0) {
showFiles(message, value); // value is the object representing Folders
}
});
});
call.fail(failHandler);
});

// showFiles implementation code
function showFiles(message, folder) {
message.append(folder.Name + ":"); // This will write the name of the Folder
// Below code will iterate through the file objects --> so in this Loop the value object represents a file
jQuery.each(folder.Files.results, function (index, value) {
message.append("<div style='padding-left:10px'>" + value.Name + "</div");
});
message.append("<br/>");
}

function failHandler(jqXHR, textStatus, errorThrown) {
var response = "";
try {
var parsed = JSON.parse(jqXHR.responseText);
response = parsed.error.message.value;
} catch (e) {
response = jqXHR.responseText;
}
alert("Call failed. Error: " + response);
}

})();

By doing following changes you can also get the resources by getting QueryString:

Click to download the file: App.js (1.75 kb)

Output:

Voila!

Add comment