DownloadsFolder DownloadsFolder DownloadsFolder Class

Definition

Creates files and folders inside the Downloads folder.

public static class DownloadsFolderpublic static class DownloadsFolderPublic Static Class DownloadsFolder
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

This class is static and cannot be instantiated. Call the methods directly instead.

File and folder permissions in the Downloads folder

All apps can create files and folders in the Downloads folder and can access the files that they create. But apps can't access files in the Downloads folder that they didn't create.

When your app creates a file in the Downloads folder, other apps can't interfere with or access your file unless the user explicitly gives the other app access. The user can give another app access to your file by selecting the file from the file picker. Your app can also use the file picker to get access to the files in the Downloads folder that it didn't create. Learn more about opening files with the file picker in Open files and folders with a picker.

Capabilities are not needed to create or access files in the Downloads folder. Learn more about capabilities in App capability declarations.

To learn more about what locations your app can access, see File access permissions.

Examples

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

Windows.Storage.DownloadsFolder.createFileAsync("sample.txt").done(
    function (file) {
        // Process file
    }
);
StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("sample.txt");
// Process file

After createFileAsync completes, file gets the new file as a StorageFile.

Methods

CreateFileAsync(String) CreateFileAsync(String) CreateFileAsync(String)

Creates a new file inside the Downloads folder.

public static IAsyncOperation<StorageFile> CreateFileAsync(String desiredName)public static IAsyncOperation<StorageFile> CreateFileAsync(String desiredName)Public Static Function CreateFileAsync(desiredName As String) As IAsyncOperation( Of StorageFile )
Parameters
desiredName
System.String System.String System.String

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.

Returns

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

Attributes

CreateFileAsync(String, CreationCollisionOption) CreateFileAsync(String, CreationCollisionOption) CreateFileAsync(String, CreationCollisionOption)

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.

public static IAsyncOperation<StorageFile> CreateFileAsync(String desiredName, CreationCollisionOption option)public static IAsyncOperation<StorageFile> CreateFileAsync(String desiredName, CreationCollisionOption option)Public Static Function CreateFileAsync(desiredName As String, option As CreationCollisionOption) As IAsyncOperation( Of StorageFile )
Parameters
desiredName
System.String System.String System.String

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

Returns

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

Attributes

CreateFileForUserAsync(User, String) CreateFileForUserAsync(User, String) CreateFileForUserAsync(User, String)

Creates a new file inside the Downloads folder of a specific User.

public static IAsyncOperation<StorageFile> CreateFileForUserAsync(User user, String desiredName)public static IAsyncOperation<StorageFile> CreateFileForUserAsync(User user, String desiredName)Public Static Function CreateFileForUserAsync(user As User, desiredName As String) As IAsyncOperation( Of StorageFile )
Parameters
user
User User User

The User for which the file is created.

desiredName
System.String System.String System.String

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.

Returns

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

Attributes

CreateFileForUserAsync(User, String, CreationCollisionOption) CreateFileForUserAsync(User, String, CreationCollisionOption) CreateFileForUserAsync(User, String, CreationCollisionOption)

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

public static IAsyncOperation<StorageFile> CreateFileForUserAsync(User user, String desiredName, CreationCollisionOption option)public static IAsyncOperation<StorageFile> CreateFileForUserAsync(User user, String desiredName, CreationCollisionOption option)Public Static Function CreateFileForUserAsync(user As User, desiredName As String, option As CreationCollisionOption) As IAsyncOperation( Of StorageFile )
Parameters
user
User User User

The User for which the file is created.

desiredName
System.String System.String System.String

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
CreationCollisionOption CreationCollisionOption 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 of the specified User, you can't specify OpenIfExists or ReplaceExisting for this parameter.

Returns

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

Attributes

CreateFolderAsync(String) CreateFolderAsync(String) CreateFolderAsync(String)

Creates a new subfolder in the Downloads folder.

public static IAsyncOperation<StorageFolder> CreateFolderAsync(String desiredName)public static IAsyncOperation<StorageFolder> CreateFolderAsync(String desiredName)Public Static Function CreateFolderAsync(desiredName As String) As IAsyncOperation( Of StorageFolder )
Parameters
desiredName
System.String System.String System.String

The desired name of the subfolder to create.

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

Returns

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

Attributes

CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption) CreateFolderAsync(String, CreationCollisionOption)

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

public static IAsyncOperation<StorageFolder> CreateFolderAsync(String desiredName, CreationCollisionOption option)public static IAsyncOperation<StorageFolder> CreateFolderAsync(String desiredName, CreationCollisionOption option)Public Static Function CreateFolderAsync(desiredName As String, option As CreationCollisionOption) As IAsyncOperation( Of StorageFolder )
Parameters
desiredName
System.String System.String System.String

The desired name of the subfolder to create.

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

option
CreationCollisionOption CreationCollisionOption CreationCollisionOption

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

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

Returns

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

Attributes

CreateFolderForUserAsync(User, String) CreateFolderForUserAsync(User, String) CreateFolderForUserAsync(User, String)

Creates a new subfolder inside the Downloads folder of a specific User.

public static IAsyncOperation<StorageFolder> CreateFolderForUserAsync(User user, String desiredName)public static IAsyncOperation<StorageFolder> CreateFolderForUserAsync(User user, String desiredName)Public Static Function CreateFolderForUserAsync(user As User, desiredName As String) As IAsyncOperation( Of StorageFolder )
Parameters
user
User User User

The User for which the folder is created.

desiredName
System.String System.String System.String

The desired name of the subfolder to create.

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

Returns

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

Attributes

CreateFolderForUserAsync(User, String, CreationCollisionOption) CreateFolderForUserAsync(User, String, CreationCollisionOption) CreateFolderForUserAsync(User, String, CreationCollisionOption)

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

public static IAsyncOperation<StorageFolder> CreateFolderForUserAsync(User user, String desiredName, CreationCollisionOption option)public static IAsyncOperation<StorageFolder> CreateFolderForUserAsync(User user, String desiredName, CreationCollisionOption option)Public Static Function CreateFolderForUserAsync(user As User, desiredName As String, option As CreationCollisionOption) As IAsyncOperation( Of StorageFolder )
Parameters
user
User User User

The User for which the folder is created.

desiredName
System.String System.String System.String

The desired name of the subfolder to create.

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

option
CreationCollisionOption CreationCollisionOption CreationCollisionOption

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

Because the app can only access folders in the Downloads folder of the specified User, you can't specify OpenIfExists or ReplaceExisting for this parameter.

Returns

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

Attributes