StorageFolder.CreateFolderAsync StorageFolder.CreateFolderAsync StorageFolder.CreateFolderAsync StorageFolder.CreateFolderAsync StorageFolder.CreateFolderAsync Method

Definition

Overloads

CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String)

Creates a new subfolder with the specified name in the current folder.

CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption)

Creates a new subfolder with the specified name in the current folder. This method also specifies what to do if a subfolder with the same name already exists in the current folder.

CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String)

Creates a new subfolder with the specified name in the current folder.

public : IAsyncOperation<StorageFolder> CreateFolderAsync(Platform::String desiredName)
IAsyncOperation<StorageFolder> CreateFolderAsync(winrt::hstring desiredName) const;
public IAsyncOperation<StorageFolder> CreateFolderAsync(String desiredName)
Public Function CreateFolderAsync(desiredName As String) As IAsyncOperation(Of StorageFolder)
Windows.Storage.StorageFolder.createFolderAsync(desiredName).done( /* Your success and error handlers */ );

Parameters

desiredName
String String String

The name of the new subfolder to create in the current folder.

Returns

When this method completes, it returns a StorageFolder that represents the new subfolder.

Exceptions

FileNotFoundException FileNotFoundException FileNotFoundException

The folder name contains invalid characters, or the format of the folder name is incorrect. Check the value of desiredName.

UnauthorizedAccessException UnauthorizedAccessException UnauthorizedAccessException

You don't have permission to create a subfolder in the current folder.

Examples

The following example shows how to create a new StorageFolder in the current folder by calling the CreateFolderAsync(String, CreationCollisionOption) overloaded method. This example explicitly specifies a value for options that causes the operation to fail if a folder with the specified desiredName already exists in the current folder.

using Windows.Storage;
using System.Threading.Tasks;

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

// Create a new subfolder in the current folder.
// Raise an exception if the folder already exists.
string desiredName = "Subfolder";
StorageFolder newFolder =
    await localFolder.CreateFolderAsync(desiredName, CreationCollisionOption.FailIfExists);
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the app's local folder.
    Windows::Storage::StorageFolder localFolder{ Windows::Storage::ApplicationData::Current().LocalFolder() };

    // Create a new subfolder in the current folder.
    // Throw an exception if it already exists.
    std::wstring desiredName{ L"Subfolder" };
    Windows::Storage::StorageFolder folder{ co_await localFolder.CreateFolderAsync(desiredName, Windows::Storage::CreationCollisionOption::FailIfExists) };

    // Do something with folder.
}
 //Get app's local folder
 StorageFolder^ localFolder = Windows::Storage::ApplicationData::Current->LocalFolder;
 
 // Create a new subfolder in the current folder
 // Raise an exception if it already exists
 String^ desiredName = "Subfolder";
 create_task(localFolder->CreateFolderAsync(desiredName,Windows::Storage::CreationCollisionOption::FailIfExists)).then([](StorageFolder^ folder)
 {
    //Do something with folder
 });
// Get the app's local folder.
var localFolder = Windows.Storage.ApplicationData.current.localFolder;

// Create a new subfolder in the current folder.
// Raise an exception if the folder already exists.
var desiredName = "Subfolder";
var CreationCollisionOption = Windows.Storage.CreationCollisionOption;
var newFolderPromise = localFolder.createFolderAsync(desiredName, CreationCollisionOption.failIfExists);
newFolderPromise.done(function createFolderSuccess(newFolder) {
    // Subfolder was created in the current folder.

}, function createFolderFail(error) {
    // Subfolder creation fails if the folder already exists. 
});

Remarks

This method uses the FailIfExists value from the CreationCollisionOption enumeration by default. That is, this method raises an exception if a subfolder with the same name already exists in the current folder. If you want to handle a folder name collision in a different way, call the CreateFolderAsync(String, CreationCollisionOption) method.

If you try to create a subfolder in a virtual folder like a library, or a folder that represents a container for a group of files (for example, the return value from some overloads of the GetFoldersAsync method), the CreateFolderAsync method may fail.

See also

CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption)

Creates a new subfolder with the specified name in the current folder. This method also specifies what to do if a subfolder with the same name already exists in the current folder.

public : IAsyncOperation<StorageFolder> CreateFolderAsync(Platform::String desiredName, CreationCollisionOption options)
IAsyncOperation<StorageFolder> CreateFolderAsync(winrt::hstring desiredName, CreationCollisionOption options) const;
public IAsyncOperation<StorageFolder> CreateFolderAsync(String desiredName, CreationCollisionOption options)
Public Function CreateFolderAsync(desiredName As String, options As CreationCollisionOption) As IAsyncOperation(Of StorageFolder)
Windows.Storage.StorageFolder.createFolderAsync(desiredName, options).done( /* Your success and error handlers */ );

Parameters

desiredName
String String String

The name of the new subfolder to create in the current folder.

options
CreationCollisionOption CreationCollisionOption CreationCollisionOption

One of the enumeration values that determines how to handle the collision if a subfolder with the specified desiredName already exists in the current folder.

Returns

When this method completes, it returns a StorageFolder that represents the new subfolder.

Exceptions

FileNotFoundException FileNotFoundException FileNotFoundException

The folder name contains invalid characters, or the format of the folder name is incorrect. Check the value of desiredName.

UnauthorizedAccessException UnauthorizedAccessException UnauthorizedAccessException

You don't have permission to create a subfolder in the current folder.

Remarks

If a folder with the specified desiredName already exists in the current folder, the specified CreationCollisionOption determines how to handle the collision.

See also