FolderPicker.PickSingleFolderAsync Methode

Definition

Zeigt ein Dialogfeld an, in dem der Benutzer einen Ordner auswählen kann.

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

Gibt zurück

Gibt ein PickFolderResult -Objekt zurück, das den Pfad des ausgewählten Ordners enthält.

Gibt zurück null , wenn das Ordnerdialogfeld ohne Auswahl abgebrochen oder geschlossen wird.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie Sie die PickSingleFolderAsync-Methode verwenden, um ein Dialogfeld für die Ordnerauswahl zu öffnen und einen Ordner auszuwählen:

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
}

Hinweise

Bei Bedarf können Sie ein Objekt in ein PickFolderResultWindows.Storage.StorageFolder Objekt konvertieren, indem Sie den Ordnerpfad aufrufen Windows.Storage.StorageFolder.GetFolderFromPathAsync .

Gilt für:

Weitere Informationen