Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

how to retrieve document library from a subsite

$
0
0

 i have a site named siteA,in which i have two subsites site1 and site2.in each subsite like site1 and site 2 there is a document library. i want to fetch the document library of selected subsite.actually i have 3 dropdown.in 1st dropdown i am selecting the site and in 2nd dropdown the respective subsite of selected subsite and in 3rd dropdown i want to show the respective document library of selected subsite.i got problem in retriving the document library.i think i made problem in url.my url for retrieving the doc lib is -

url: "https://fte-teams.cbreglobalinvestors.com/sites/dev/"+value1+"/_api/web/Lists?$filter=BaseTemplate eq 101 and Title ne 'Site Assets' and Title ne 'Style Library'",

here value 1 having the selected site and value having selected subsite.full code is given below.plz help in retrieving the document library of selected subsite.

<!DOCTYPE html>
<head>
<script src="https://fte-teams.cbreglobalinvestors.com/sites/dev/Shared%20Documents/jquery-3.1.1.js"></script>
<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(RetriveSites,"sp.js");

//retrieve sites

function RetriveSites()
{

$.ajax({
    url: "https://fte-teams.cbreglobalinvestors.com/sites/dev/_api/web/webs?$select=Title,Url,ServerRelativeUrl",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function(data) {
        var subSiteNames = [];
        var subSiteURL=[]; 
        $.each(data.d.results, function(index, item) {
            subSiteNames.push(item.Title);
            subSiteURL.push(item.Url);
        });
        console.log(subSiteNames);
console.log(subSiteURL);
var select = document.getElementById("selectSite");
for(var i = 0; i < subSiteNames.length; i++) {
    var opt = subSiteNames[i];
    var el = document.createElement("option");
    el.textContent = opt;
    el.value1 = opt;
    select.appendChild(el);
  }
}  
});
}

//retrieve subsites

function siteName(value1)
{
alert(value1);
var SiteURL="https://fte-teams.cbreglobalinvestors.com/sites/dev/"+value1;
alert(SiteURL)
subSiteName(value1);
$('#SubSites option').each(function () {
                if ($(this).val() != '2') {
                    $(this).remove();
                }
            });

}

function subSiteName(value1)
{
alert(value1)
$.ajax({
    url: "https://fte-teams.cbreglobalinvestors.com/sites/dev/"+value1+"/_api/web/webs?$select=Title,Url,ServerRelativeUrl",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
success: function(data) {
        var Names = [];
        var NamesURL=[]; 
        $.each(data.d.results, function(index, item) {
            Names.push(item.Title);
            NamesURL.push(item.Url);
        });
        console.log(Names);
alert(Names);
console.log(NamesURL);
var select=0;
var select = document.getElementById("SubSites");
for(var i = 0; i< Names.length; i++) {
    var opt = Names[i];
    var el = document.createElement("option");
    el.textContent = opt;
    el.value = opt;
    select.appendChild(el);
}
}
});
}
//retrieve document library
function suSiteName(value)
{
alert(value);
var suSiteURL="https://fte-teams.cbreglobalinvestors.com/sites/dev/"+value1;
alert(suSiteURL)
suSiteName(value);

}
function retriveDocLib()
{

$.ajax({
    url: "https://fte-teams.cbreglobalinvestors.com/sites/dev/"+value1+"/_api/web/Lists?$filter=BaseTemplate eq 101 and Title ne 'Site Assets' and Title ne 'Style Library'",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function(data) {
        var docLibNames = [];
        var docLibURL=[]; 
        $.each(data.d.results, function(index, item) {
           docLibNames.push(item.Title);
           docLibURL.push(item.Url);
        });
        console.log(docLibNames);
alert(docLibNames);
console.log(docLibURL);
var select = document.getElementById("selectDocLib");
for(var i = 0; i < docLibNames.length; i++) {
    var opt = docLibNames[i];
    var el = document.createElement("option");
    el.textContent = opt;
    el.value = opt;
    select.appendChild(el);
  }
}  
});
}
</script>
</head>


<body>

<div id="ddlSub">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   SelectSite:<select id="selectSite" onchange="siteName(this.value);">
    <option value="ChooseSite">Choose a Site</option>
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


    SelectSubSite:<select id="SubSites" onchange="subSiteName(this.value);">
<option value="2">Choose a SubSite</option></select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


SelectDocLib:<select id="selectDocLib" onchange="suSiteName(this.value);">
    <option value="3">Choose a Document Library</option>
</select>
</div>
</body>
</html>


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>