Condividi tramite


SP.Folder Class

Applies to: SharePoint Foundation 2010

Represents a folder on a SharePoint website.

SP.Folder

Inherits

SP.ClientObject Class

Remarks

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

Example

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>

See Also

Reference

SP.Folder Methods

SP.Folder Properties

SP Namespace