FileOpenPicker.PickMultipleFilesAsync Methode

Definition

Zeigt ein Dialogfeld an, in dem Benutzer mehrere Dateien auswählen und öffnen können.

public:
 virtual IAsyncOperation<IVectorView<PickFileResult ^> ^> ^ PickMultipleFilesAsync() = PickMultipleFilesAsync;
IAsyncOperation<IVectorView<PickFileResult>> PickMultipleFilesAsync();
public IAsyncOperation<IReadOnlyList<PickFileResult>> PickMultipleFilesAsync();
function pickMultipleFilesAsync()
Public Function PickMultipleFilesAsync () As IAsyncOperation(Of IReadOnlyList(Of PickFileResult))

Gibt zurück

Gibt eine Auflistung von PickFileResult -Objekten zurück, die den Pfad der ausgewählten Dateien enthalten.

Gibt eine leere Liste (IReadOnlyList.Count = 0) zurück, wenn das Dialogfeld ohne Auswahl abgebrochen oder geschlossen wird.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die PickMultipleFilesAsync-Methode zum Öffnen eines Dateiauswahldialogfelds verwendet und der Inhalt der ausgewählten Dateien gelesen wird:

using Microsoft.Windows.Storage.Pickers;

var openPicker = new FileOpenPicker(this.AppWindow.Id);
var results = await openPicker.PickMultipleFilesAsync();

if (results.Count > 0)
{
    var pickedFilePaths = results.Select(f => f.Path);
    foreach (var path in pickedFilePaths)
    {
        var content = System.IO.File.ReadAllText(path);
    }
}
else
{
    // Add error handling logic here
}
#include <winrt/Microsoft.Windows.Storage.Pickers.h>
#include <fstream>
#include <string>
using namespace winrt::Microsoft::Windows::Storage::Pickers;

FileOpenPicker openPicker(AppWindow().Id());
auto& results{ co_await openPicker.PickMultipleFilesAsync() };

if (results.Size() > 0)
{
    for (auto const& result : results)
    {
        std::ifstream fileReader(result.Path().c_str());
        std::string text((std::istreambuf_iterator<char>(fileReader)), std::istreambuf_iterator<char>());
        winrt::hstring hText = winrt::to_hstring(text);
    }
}
else
{
    // Add error handling logic here
}

Gilt für: