Export (0) Print
Expand All

SP.Folder Class

SharePoint 2010

Last modified: July 06, 2010

Applies to: SharePoint Foundation 2010

Represents a folder on a SharePoint website.

SP.Folder

The UniqueContentTypeOrder property is not included in the default scalar property set for this type.

The following example creates an input button on an application page that lists the folders on the current website.

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

    var folderCollection;
    function runCode() {

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

            this.folderCollection = web.get_folders();

            clientContext.load(this.folderCollection);

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

    function onQuerySucceeded(sender, args) {
        var folderInfo = 'The current site contains the following folders:\n\n';
        var folderEnumerator = this.folderCollection.getEnumerator();
        while (folderEnumerator.moveNext()) {
            var folderItem = folderEnumerator.get_current();
            folderInfo += folderItem.get_name() + '\n';
        }
        alert(folderInfo);
    }

    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