每当我尝试此代码时:
foreach (StorageFile filesAsync in await folderFromPathAsync.GetFolderAsync(_selectedPlayList).GetFilesAsync())//Error here
{
this._fileNames.Add(filesAsync.Name.Substring(0, filesAsync.Name.LastIndexOf('.')));
this.FilesListBox.Items.Add(filesAsync.Name.Substring(0, filesAsync.Name.LastIndexOf('.')));
this._pathNames.Add(filesAsync.Path);
}
由于某种奇怪的原因,GetFilesAsync()定义不存在。这是我的错吗?我的完整错误信息:
'Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFolder>'
不包含"GetFilesAsync"的定义,也找不到接受"Windows.Foundation.IAsyncOperation"类型的第一个参数的扩展方法"GetFiles异步"(是否缺少using指令或程序集引用?)
请帮助我
您正试图根据调用GetFolderAsync()
的结果来调用GetFilesAsync()
,而您应该等待GetFolderAsync()
的结果,然后根据等待的结果调用GetFilesAsync()
。GetFolderAsync()
的返回值不是文件夹,而是获取文件夹的异步操作。(这是IAsyncOperation<StorageFolder>
,而不是StorageFolder
。)
例如:
var folder = await folderFromPathAsync.GetFolderAsync(_selectedPlayList);
foreach (var file in await folder.GetFilesAsync())
{
...
}