Skip to main content
StorageFolder.GetFolderAsync | getFolderAsync method

Gets the subfolder with the specified name from the current folder.

Syntax


storageFolder.getFolderAsync(name).done( /* Your success and error handlers */ );

public IAsyncOperation<StorageFolder> GetFolderAsync(
  string name
)

Public Function GetFolderAsync(
  name As String 
) As IAsyncOperation(Of StorageFolder)

public:
IAsyncOperation<StorageFolder>^ GetFolderAsync(
  String^ name
)

Parameters

name

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

The name (or path relative to the current folder) of the subfolder to get.

Return value

Type: IAsyncOperation<StorageFolder>

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

Exceptions

ExceptionCondition
System.IO.FileNotFoundException

The specified folder does not exist. Check the value of name.

System.UnauthorizedAccessException

You don't have permission to access the specified folder.

System.ArgumentException

The path cannot be in Uri format (for example, /Assets). Check the value of name.

Examples

The following example shows how to get a subfolder from the current folder by calling the GetFolderAsync method. This example also shows how to get a subfolder from a subfolder of the current folder by providing a relative path.


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

            // Create 2 levels of subfolders in the app's local folder.
            string name1 = "Subfolder1";
            StorageFolder subFolder1 =
                await localFolder.CreateFolderAsync(name1);
            string name2 = "Subfolder2";
            StorageFolder subFolder2 =
                await subFolder1.CreateFolderAsync(name2);

            // Get the subfolder of the app's local folder.
            string level1FolderName = "Subfolder1";
            StorageFolder level1Folder =
                await localFolder.GetFolderAsync(level1FolderName);

            // Get the subfolder of the subfolder
            // by providing a relative path.
            string level2FolderName = @"Subfolder1\Subfolder2";
            StorageFolder level2Folder =
                await localFolder.GetFolderAsync(level2FolderName);

// Get the app's local folder.
var localFolder = Windows.Storage.ApplicationData.current.localFolder;

// Create 2 levels of subfolders in the app's local folder.
var name1 = "Subfolder1";
var subFolder1Promise = localFolder.createFolderAsync(name1);
var subFolder2Promise = subFolder1Promise.then(function createFolder1Success(subFolder1) {

    var name2 = "Subfolder2";
    return subFolder1.createFolderAsync(name2);
});
var level1FolderPromise = subFolder1Promise.then(function createFolder1Success(subFolder1) {

    // Get the subfolder of the app's local folder.
    var level1FolderName = "Subfolder1";
    return localFolder.getFolderAsync(level1FolderName);
});
level1FolderPromise.done(function (level1Folder) {

});
var level2FolderPromise = subFolder2Promise.then(function createFolder2Success(subFolder2) {

    // Get the subfolder of the subfolder
    // by providing a relative path.
    var level2FolderName = "Subfolder1\\Subfolder2";
    return localFolder.getFolderAsync(level2FolderName);
});
level2FolderPromise.done(function getFolderSuccess(level2Folder) {

});

 // Get the app's local folder
 StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;

 // Create 2 levels of subfolders in the app's local folder.
 String^ name1 = "Subfolder1";
 String^ name2 = "Subfolder2";
 String^ level2FolderName = "Subfolder1\\Subfolder2";

 create_task(localFolder->CreateFolderAsync(name1)).then([=](StorageFolder^ subFolder1) -> task <StorageFolder^> {
  return create_task(subFolder1->CreateFolderAsync(name2));
 }).then([=](StorageFolder^ subFolder2) -> task<StorageFolder^> {
 // Get the subfolder of the subfolder
 // by providing a relative path.
  return create_task(localFolder->GetFolderAsync(level2FolderName));
 });

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

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
GetItemAsync