StorageFolder.DeleteAsync StorageFolder.DeleteAsync StorageFolder.DeleteAsync StorageFolder.DeleteAsync StorageFolder.DeleteAsync Method

Definition

Overloads

DeleteAsync() DeleteAsync() DeleteAsync() DeleteAsync() DeleteAsync()

Deletes the current folder.

DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption)

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

DeleteAsync() DeleteAsync() DeleteAsync() DeleteAsync() DeleteAsync()

Deletes the current folder.

public : IAsyncAction DeleteAsync()
IAsyncAction DeleteAsync() const;
public IAsyncAction DeleteAsync()
Public Function DeleteAsync() As IAsyncAction
Windows.Storage.StorageFolder.deleteAsync().done( /* Your success and error handlers */ );
Returns

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

Exceptions
UnauthorizedAccessException UnauthorizedAccessException 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) overloaded method. This example explicitly specifies a value for option that deletes the file permanently.

using Windows.Storage;
using System.Threading.Tasks;
using System.Diagnostics; // For writing results to Output window.

// Get the app's local folder.
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

// Create a temporary folder in the current folder.
string folderName = "Test";
StorageFolder testFolder = await localFolder.CreateFolderAsync(folderName);

// Has the folder been created?
if(await localFolder.TryGetItemAsync(folderName) != null)
    Debug.WriteLine("Folder " + folderName + " exists.");
else
    Debug.WriteLine("Folder " + folderName + " does not exist.");

// Delete the folder permanently.
await testFolder.DeleteAsync(StorageDeleteOption.PermanentDelete);

// Has the folder been deleted?
if(await localFolder.TryGetItemAsync(folderName) != null)
    Debug.WriteLine("Folder " + folderName + " exists.");
else
    Debug.WriteLine("Folder " + folderName + " does not exist.");
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    Windows::Storage::StorageFolder localFolder{ Windows::Storage::ApplicationData::Current().LocalFolder() };

    std::wstring folderName{ L"test" };

    Windows::Storage::StorageFolder newFolder{ co_await localFolder.CreateFolderAsync(folderName) };

    {
        // Check that the folder exists.
        Windows::Storage::IStorageItem newItem{ co_await localFolder.TryGetItemAsync(folderName) };
        std::wstringstream stringstream;
        stringstream << L"Folder: " << folderName.c_str();
        if (newItem)
        {
            stringstream << L" created" << std::endl;
        }
        else
        {
            stringstream << L" not found" << std::endl;
        }
        ::OutputDebugString(stringstream.str().c_str());
    }

    co_await newFolder.DeleteAsync(Windows::Storage::StorageDeleteOption::PermanentDelete);

    {
        // Check that the folder has been deleted.
        Windows::Storage::IStorageItem newItem{ co_await localFolder.TryGetItemAsync(folderName) };
        std::wstringstream stringstream;
        stringstream << L"Folder: " << folderName.c_str();
        if (newItem)
        {
            stringstream << L" not deleted" << std::endl;
        }
        else
        {
            stringstream << L" deleted" << std::endl;
        }
        ::OutputDebugString(stringstream.str().c_str());
    }
}
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;

String^ folderName = "test";

create_task(localFolder->CreateFolderAsync(folderName)).then([=](StorageFolder^ newFolder) -> task<IStorageItem^> {
    //Check the folder exists
    return create_task(localFolder->TryGetItemAsync(folderName));
}).then([=](IStorageItem^ newFolder) -> task<void> {
    String^ output = "";
    if (newFolder == nullptr)
    {
        output = "Folder: " + folderName + " not found
"; } else { output = "Folder: " + folderName + " created
"; } OutputDebugString(output->Begin()); return create_task(newFolder->DeleteAsync(StorageDeleteOption::PermanentDelete)); }).then([=]() -> task<IStorageItem^> { return create_task(localFolder->TryGetItemAsync(folderName)); }).then([=](IStorageItem^ newFolder) { String^ output = ""; if (newFolder == nullptr) { output = "Folder: " + folderName + " deleted
"; } else { output = "Folder: " + folderName + " not deleted
"; } OutputDebugString(output->Begin()); });
// 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.");
    }
});

Remarks

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

See Also

DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption)

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

public : IAsyncAction DeleteAsync(StorageDeleteOption option)
IAsyncAction DeleteAsync(StorageDeleteOption option) const;
public IAsyncAction DeleteAsync(StorageDeleteOption option)
Public Function DeleteAsync(option As StorageDeleteOption) As IAsyncAction
Windows.Storage.StorageFolder.deleteAsync(option).done( /* Your success and error handlers */ );
Parameters
option
StorageDeleteOption StorageDeleteOption StorageDeleteOption

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

Returns

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

Exceptions
UnauthorizedAccessException UnauthorizedAccessException UnauthorizedAccessException

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

See Also