DeleteAsync() | deleteAsync() method
Collapse the table of content
Expand the table of content

StorageFolder.DeleteAsync() | deleteAsync() method

Deletes the current folder.

Syntax


storageFolder.deleteAsync().done( /* Your success and error handlers */ );

Parameters

This method has no parameters.

Return value

Type: IAsyncAction

No object or value is returned by this method when it completes.

Exceptions

ExceptionCondition
System.UnauthorizedAccessException

You don't have permission to delete the specified folder.

Remarks

This method implicitly uses StorageDeleteOption.Default to determine whether the item is deleted permanently.

Examples

The following example shows how to delete the current folder by calling the DeleteAsync() method.


// Get the app's local folder.
var localFolder = Windows.Storage.ApplicationData.current.localFolder;

// Create a temporary folder in the current folder.
var folderName = "Test";
var testFolderPromise = localFolder.createFolderAsync(folderName);
var getItemPromise = testFolderPromise.then(null, function createFolderFail(error) {

    // Folder creation failed.
    // Does the folder already exist?
    return localFolder.tryGetItemAsync(folderName);
});
var deleteItemPromise = getItemPromise.then(function getItemSuccess(testFolder) {
    if (testFolder !== null) {
        console.log("Folder", folderName, "exists.");
    } else {
        console.log("Folder", folderName, "does not exist.");
    }

    // Delete the folder.
    return testFolder && testFolder.deleteAsync();
});
var getDeletedItemPromise = deleteItemPromise.then(function deleteSuccess() {

    // Has the folder been deleted?
    return localFolder.tryGetItemAsync(folderName);
});
getDeletedItemPromise.done(function getDeletedItemSuccess(item) {
    if (item !== null) {
        console.log("Folder", folderName, "exists.");
    } else {
        console.log("Folder", folderName, "does not exist.");
    }
});

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

StorageFolder
DeleteAsync(StorageDeleteOption)

 

 

Show:
© 2016 Microsoft