Get all subsites information using SharePoint client object model

InfoPath alternatives for form designing SharePoint

In this article I will show you how to get all sub sites information using client object model in SharePoint 2013.

Read some SharePoint 2013 tutorials below:

Create a page and content editor webpart. And add the below piece of code.




<script>
ExecuteOrDelayUntilScriptLoaded(RetriveSites,”sp.js”);
function RetriveSites()
{
currentcontext = new SP.ClientContext.get_current();
currentweb = currentcontext.get_web();
//this.subsites = currentweb.get_webs();
this.subsites = currentweb.getSubwebsForCurrentUser(null);
currentcontext.load(this.subsites);
currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
Function.createDelegate(this, this.ExecuteOnFailure));
}

function ExecuteOnSuccess(sender, args) {
var subsites = ”;
var enum1 = this.subsites.getEnumerator();
var el = document.getElementById(‘LKMSubWebs’);
while (enum1.moveNext())
{
var Site = enum1.get_current();
//alert(‘hi123’);
subsites += ‘\n’ + ‘<a class=subsitecls href=’+ Site.get_serverRelativeUrl()+’>’+Site.get_title()+'</a> </br>’
//RootElement.append(‘<a class=subsitecls href=’+ siteTitle+’>’+siteTitle+'</a> </br>’);
//alert(subsites);
}
el.innerHTML = subsites;
}

function ExecuteOnFailure(sender, args) {
alert(“error”);
//alert(args.get_message());
}
</script>

<div id=”LKMSubWebs”></div>

This will bind all the subsites titles and will display them.

Hope this helps some one.

Similar SharePoint 2013 Tutorials


Leave a Reply