Saturday, 3 September 2011

Get all subsites Ecmascript\Javascript client object model sharepoint 2010


An example of how to get all the subsites in a site collection

<script type="text/javascript">

var currentcontext = null;
var currentweb = null;

ExecuteOrDelayUntilScriptLoaded(RetriveSites, "sp.js");

function RetriveSites()
{
currentcontext = new SP.ClientContext.get_current();

currentweb = currentcontext.get_web();

this.subsites = currentweb.get_webs();

currentcontext.load(this.subsites);

currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
Function.createDelegate(this, this.ExecuteOnFailure));

}

function ExecuteOnSuccess(sender, args) {
var subsites = '';

var enum = this.subsites.getEnumerator();

while (enum.moveNext())
{
var Site = enum.get_current();
subsites += '\nID: ' + Site.get_id() + '\nTitle: ' + Site.get_title();

}
alert(subsites);
}

function ExecuteOnFailure(sender, args) {
alert("error");
}
</script>

Ads by Google

2 comments:

  1. The simple truth is I like this article, the author's writing was very honest, very clever writing skills.

    Nersha
    www.gofastek.com

    ReplyDelete
  2. Hi!,

    I tested and works, but only for people that have atleast permissions of Contribute…why?, the visitors have the follow message:

    Access denied. You do not have permission to perform this action or access this resource.

    Could you helpme?

    ReplyDelete