SP.Web Class

Applies to: SharePoint Foundation 2010

Represents a Microsoft SharePoint Foundation website.



SP.SecurableObject Class


The following example creates an input button on an application page that displays information about a subweb.

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

    var targetWeb;

    function runCode() {
        // Specify a client context using the server-relative URL of the sub web, load the sub web, and call the ExecuteQueryAsync method.
        var clientContext = new SP.ClientContext('/MySubWeb');
        targetWeb = clientContext.get_web();
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    function onQuerySucceeded() {
        // On success, use get_ property assessor methods to return the value of the Title, ID, Language, uiVersion, Description, and Created properties of the SP.Web object.
        var message = "Web retrieved:";
        message += "\n Title: " + targetWeb.get_title();
        message += "\n ID: " + targetWeb.get_id();
        message += "\n Language: " + targetWeb.get_language();
        message += "\n UI Version: " + targetWeb.get_uiVersion();
        message += "\n Description: " + targetWeb.get_description();
        message += "\n Created: " + targetWeb.get_created();

    function onQueryFailed(sender, args) {
        alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());


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


See Also


SP.Web Methods

SP.Web Properties

SP Namespace