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

Applies to Windows only

Creates a new file inside the Downloads folder.

Syntax


public static IAsyncOperation<StorageFile> CreateFileAsync(
  string desiredName
)

Parameters

desiredName

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

The desired name of the file to create.

If a file with the specified name already exists, a similar but unique name will be used. For example, if desiredName is "MyFileName.jpg" and a file by that name already exists in the Downloads folder, the new file will be created with a name like "MyFileName (1).jpg" instead.

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, CreationCollisionOption)

 

 

Show:
© 2014 Microsoft