Share via


FolderPicker.PickSingleFolderAsync Method

Definition

Displays a dialog that allows the user to select a folder.

public:
 virtual IAsyncOperation<PickFolderResult ^> ^ PickSingleFolderAsync() = PickSingleFolderAsync;
IAsyncOperation<PickFolderResult> PickSingleFolderAsync();
public IAsyncOperation<PickFolderResult> PickSingleFolderAsync();
function pickSingleFolderAsync()
Public Function PickSingleFolderAsync () As IAsyncOperation(Of PickFolderResult)

Returns

Returns a PickFolderResult object that contains the path of the picked folder.

Returns null if the folder dialog is canceled or closed without selection.

Examples

The following example demonstrates how to use the PickSingleFolderAsync method to open a folder picker dialog and select a folder:

using Microsoft.Windows.Storage.Pickers;

var folderPicker = new FolderPicker(this.AppWindow.Id);
var result = await folderPicker.PickSingleFolderAsync();
if (result is not null)
{
    var path = result.Path;
}
else
{
    // Add error handling logic here
}
#include <winrt/Microsoft.Windows.Storage.Pickers.h>
using namespace winrt::Microsoft::Windows::Storage::Pickers;

FolderPicker folderPicker(AppWindow().Id());
auto& result{ co_await folderPicker.PickSingleFolderAsync() };
if (result)
{
    auto path{ result.Path() };
}
else
{
    // Add error handling logic here
}

Remarks

If necessary, you can convert a PickFolderResult object to a Windows.Storage.StorageFolder object by calling Windows.Storage.StorageFolder.GetFolderFromPathAsync with the folder path.

Applies to

See also