Export (0) Print
Expand All

SP.Utilities.Utility Class

SharePoint 2010

Last modified: May 01, 2011

Applies to: SharePoint Foundation 2010

Provides tools for converting date and time formats, for obtaining information from user names, for modifying access to sites, and for various other tasks in managing deployment.

SP.Utilities.Utility

The following example creates an Input button on an application page that displays the URLs of the home page and home page sample photograph of the current website.

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

    var imageUrl;
    var pageUrl;
    function runCode() {
        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            this.imageUrl = SP.Utilities.Utility.getImageUrl('homepageSamplePhoto.jpg');
            this.pageUrl = SP.Utilities.Utility.getLayoutsPageUrl('Home.aspx');

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
        }
    }

    function onSuccessMethod(sender, args) {
        alert('Sample photo Url: ' + this.imageUrl + '\n\nHome page Url: ' + this.pageUrl);
    }

    function onFailureMethod(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:
© 2015 Microsoft