-1

每当我尝试这段代码时:

  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”类型的第一个参数的扩展方法“GetFilesAsync”(您是否缺少 using 指令或程序集引用?)

请帮我

4

1 回答 1

1

您正在尝试调用调用GetFilesAsync()的结果GetFolderAsync()- 而您应该等待结果GetFolderAsync()然后调用等待的结果GetFilesAsync()。来自的返回值GetFolderAsync()不是文件夹 - 它是获取文件夹的异步操作。(这是一个IAsyncOperation<StorageFolder>,而不是一个StorageFolder。)

例如:

var folder = await folderFromPathAsync.GetFolderAsync(_selectedPlayList);
foreach (var file in await folder.GetFilesAsync())
{
    ...
}
于 2014-11-13T18:01:51.243 回答