StorageFolder.CreateFolderAsync(String, CreationCollisionOption) | createFolderAsync(String, CreationCollisionOption) method

Applies to Windows and Windows Phone

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.

Syntax


storageFolder.createFolderAsync(desiredName, options).done( /* Your success and error handlers */ );

Parameters

desiredName

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

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

options

Type: 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.

Return value

Type: IAsyncOperation<StorageFolder>

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

Exceptions

ExceptionCondition
System.IO.FileNotFoundException

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

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

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.

Examples

The following example shows how to create a new StorageFolder in the current folder by calling the CreateFolderAsync(String, CreationCollisionOption) 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.


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

Requirements

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
CreateFolderAsync(String)

 

 

Show:
© 2014 Microsoft