Export (0) Print
Expand All

SP.Web.getSubwebsForCurrentUser(query_) Method

SharePoint 2010

Last modified: May 27, 2011

Applies to: SharePoint Foundation 2010

In this article
Return Value
Applies To
Remarks

Returns the collection of child sites of the current site based on the specified query.

var value = SP.Web.getSubwebsForCurrentUser(query_);

query_

Specifies which child sites to return.

Type: SP.SubwebQuery

If the query is not valid, the server must return an empty collection.

The following example creates an input button on an application page that displays the titles of the child sites of the current site.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    var webCollection = null;
    function runCode() {

        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();

            this.webCollection = web.getSubwebsForCurrentUser(null);

            clientContext.load(this.webCollection);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {
        var webInfo = 'Child sites of the current site: \n\n';
        var webEnumerator = this.webCollection.getEnumerator();
        while (webEnumerator.moveNext()) {
            var web = webEnumerator.get_current();
            webInfo += web.get_title() + '\n';
        }
        alert(webInfo);
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>
Show:
© 2014 Microsoft