StorageFolder.DeleteAsync(StorageDeleteOption) | deleteAsync(StorageDeleteOption) method

Deletes the current folder. This method also specifies whether to delete the folder permanently.

Syntax


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

Parameters

option

Type: StorageDeleteOption

One of the enumeration values that specifies whether to delete the folder permanently.

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.

Examples

The following example shows how to delete the current folder by calling the DeleteAsync(StorageDeleteOption) method. This example explicitly specifies a value for option that deletes the file permanently.


// 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.
    var StorageDeleteOption = Windows.Storage.StorageDeleteOption;
    return testFolder && testFolder.deleteAsync(StorageDeleteOption.permanentDelete);
});
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 (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

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

 

 

Show:
© 2015 Microsoft