1

I want get list of all the pages that are in pages library of each site/subsites in SharePoint Online. Can this be achieved with REST api or jQuery ? If so how? Anything is fine either Rest or jQuery.

Thanks

1

You can use Jquery and Rest Api to perform the same. Refer the code below:

var oPagesCollection=[];//object having url for all pages under root site and sub site
getPage("") //to get pages from root site

//call for first level subsite
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title",
method: "GET",
headers: {
    "Accept": "application/json; odata=verbose"
},
success: function(subsites) {
    $.each(subsites.d.results, function() {
        getSubSites(this.ServerRelativeUrl, this.Title);
        getPage(this.ServerRelativeUrl);
    });
    console.log(oPagesCollection);
},
error: function(subsites) {},
async: false
});

//function to get n level of subsites
function getSubSites(SubSiteUrl, SubSiteTitle) {
console.log(SubSiteUrl);
$.ajax({
    url: _spPageContextInfo.siteAbsoluteUrl + SubSiteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title",
    method: "GET",
    headers: {
        "Accept": "application/json; odata=verbose"
    },
    success: function(subsites) {

        $.each(subsites.d.results, function(index) {
            getSubSites(this.ServerRelativeUrl, this.Title);
            getPage(this.ServerRelativeUrl);
        });
    },
    error: function(subsites) {},
    async: false
});
}

function getPage(siteUrl){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl+ siteUrl + "/_api/web/lists/GetByTitle('Pages')/items?$select=FileRef",
method: "GET",
headers: {
    "Accept": "application/json; odata=verbose"
},
success: function(data) {
    $.each(data.d.results,function(index,val){
        oPagesCollection.push(val["FileRef"]);
    });
},
error: function(rootsite) {},
async: false
});
}
  • @SantoshS mark it as answer then.... – Ankitkumar Malde Dec 2 '16 at 4:15
  • marked it Ankit – Santosh S Dec 2 '16 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.