Share via


SP.UsageInfo Class

Applies to: SharePoint Foundation 2010

Provides fields that are used to access information about site collection usage.

SP.UsageInfo

Inherits

SP.ClientValueObject Class

Example

The following example creates an input button on an application page that displays usage information about the current site.

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

    var usageInfo;
    var site;
    var clientContext;
    function runCode() {
        this.clientContext = new SP.ClientContext.get_current();
        if (this.clientContext != undefined && this.clientContext != null) {
            this.site = clientContext.get_site();
            this.clientContext.load(this.site, 'Usage');
            this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {
        this.usageInfo = this.site.get_usage();
        var info = 'Storage: ' + this.usageInfo.get_storage() + '\nStorage percentage: ' + this.usageInfo.get_storagePercentageUsed() + '\nVisits: ' + this.usageInfo.get_visits();
        alert(info);
    }

    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>

See Also

Reference

SP.UsageInfo Methods

SP.UsageInfo Properties

SP Namespace