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

Applies to Windows and Windows Phone

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

Syntax


storageFolder.createFileAsync(desiredName).done( /* Your success and error handlers */ );

Parameters

desiredName

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

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

Return value

Type: IAsyncOperation<StorageFile>

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

Exceptions

ExceptionCondition
System.IO.FileNotFoundException

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

System.UnauthorizedAccessException

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

Remarks

This method uses the FailIfExists value from the CreationCollisionOption enumeration. If you want to handle a file name collision in a different way, call the CreateFileAsync(System.String,Windows.Storage.CreationCollisionOption) method.

If you try to create a file in a virtual folder like a library, this method may fail.

Examples

The following example shows how to create a new StorageFile in the current folder by calling the CreateFileAsync (System.String) method.


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

            // Create a new file in the current folder.
            string desiredName = "test.txt";
            StorageFile newFile = await localFolder.CreateFileAsync(desiredName);


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
CreateFileAsync(String, CreationCollisionOption)

 

 

Show:
© 2014 Microsoft