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.

function RetriveSites()
currentcontext = new SP.ClientContext.get_current();
currentweb = currentcontext.get_web();
//this.subsites = currentweb.get_webs();
this.subsites = currentweb.getSubwebsForCurrentUser(null);
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();
subsites += ‘\n’ + ‘<a class=subsitecls href=’+ Site.get_serverRelativeUrl()+’>’+Site.get_title()+'</a> </br>’
//RootElement.append(‘<a class=subsitecls href=’+ siteTitle+’>’+siteTitle+'</a> </br>’);
el.innerHTML = subsites;

function ExecuteOnFailure(sender, args) {

<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