FileOpenPicker.PickMultipleFilesAsync Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Affiche une boîte de dialogue qui permet aux utilisateurs de sélectionner et d’ouvrir plusieurs fichiers.
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))
Retours
Retourne une collection d’objets PickFileResult qui a le chemin d’accès des fichiers sélectionnés.
Renvoie une liste vide (IReadOnlyList.Count = 0) si la boîte de dialogue est annulée ou fermée sans sélection.
Exemples
L’exemple suivant montre comment utiliser la méthode PickMultipleFilesAsync pour ouvrir une boîte de dialogue sélecteur de fichiers et lire le contenu des fichiers sélectionnés :
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
}