Jaa


StorageFolder.CreateFolderAsync Method

Definition

Overloads

CreateFolderAsync(String)

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

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)

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

public:
 virtual IAsyncOperation<StorageFolder ^> ^ CreateFolderAsync(Platform::String ^ desiredName) = CreateFolderAsync;
/// [Windows.Foundation.Metadata.Overload("CreateFolderAsyncOverloadDefaultOptions")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFolder> CreateFolderAsync(winrt::hstring const& desiredName);
[Windows.Foundation.Metadata.Overload("CreateFolderAsyncOverloadDefaultOptions")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFolder> CreateFolderAsync(string desiredName);
function createFolderAsync(desiredName)
Public Function CreateFolderAsync (desiredName As String) As IAsyncOperation(Of StorageFolder)

Parameters

desiredName
String

Platform::String

winrt::hstring

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.

Implements

M:Windows.Storage.IStorageFolder.CreateFolderAsync(System.String) M:Windows.Storage.IStorageFolder.CreateFolderAsync(Platform::String) M:Windows.Storage.IStorageFolder.CreateFolderAsync(winrt::hstring)
Attributes

Exceptions

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

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
});

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

Applies to

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:
 virtual IAsyncOperation<StorageFolder ^> ^ CreateFolderAsync(Platform::String ^ desiredName, CreationCollisionOption options) = CreateFolderAsync;
/// [Windows.Foundation.Metadata.Overload("CreateFolderAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFolder> CreateFolderAsync(winrt::hstring const& desiredName, CreationCollisionOption const& options);
[Windows.Foundation.Metadata.Overload("CreateFolderAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFolder> CreateFolderAsync(string desiredName, CreationCollisionOption options);
function createFolderAsync(desiredName, options)
Public Function CreateFolderAsync (desiredName As String, options As CreationCollisionOption) As IAsyncOperation(Of StorageFolder)

Parameters

desiredName
String

Platform::String

winrt::hstring

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

options
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.

Implements

M:Windows.Storage.IStorageFolder.CreateFolderAsync(System.String,Windows.Storage.CreationCollisionOption) M:Windows.Storage.IStorageFolder.CreateFolderAsync(Platform::String,Windows.Storage.CreationCollisionOption) M:Windows.Storage.IStorageFolder.CreateFolderAsync(winrt::hstring,Windows.Storage.CreationCollisionOption)
Attributes

Exceptions

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

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

Applies to