DownloadsFolder.CreateFileAsync(String, CreationCollisionOption) | createFileAsync(String, CreationCollisionOption) method

Applies to Windows only

Creates a new file in the Downloads folder, and specifies what to do if a file with the same name already exists in the Downloads folder.

Syntax


Windows.Storage.DownloadsFolder.createFileAsync(desiredName, option).done( /* Your success and error handlers */ );

Parameters

desiredName

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

The desired name of the file to create.

If there is an existing file in the current folder that already has the specified desiredName, the specified CreationCollisionOption determines how Windows responds to the conflict.

option

Type: CreationCollisionOption

The enum value that determines how Windows responds if the desiredName is the same as the name of an existing file in the current folder.

Because the app can only access files in the Downloads folder that it created, you can't specify OpenIfExists or ReplaceExisting for this parameter.

Return value

Type: IAsyncOperation<StorageFile>

When this method completes, it returns the new file as a StorageFile object.

Remarks

All apps automatically have permission to create files in the Downloads folder. No capability is needed. Learn more about capabilities in Access to user resources using the Windows Runtime.

Examples

You can create an empty file in the Downloads folder like this:


Windows.Storage.DownloadsFolder.createFileAsync("sample.txt").done(function (file) {
        // Your code
    });

Write to the empty file after it is created by using then or done to declare a function that captures the file as a StorageFile object (as the example shows).

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

See also

DownloadsFolder
CreateFileAsync(String)

 

 

Show:
© 2014 Microsoft. All rights reserved.