Whenever i try this code:
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);
}
The definition GetFilesAsync() doesnt exist for some weird reason.Is this a fault of me? My full error message:
'Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFolder>'
does not contain a definition for 'GetFilesAsync' and no extension method 'GetFilesAsync' accepting a first argument of type 'Windows.Foundation.IAsyncOperation' could be found(are you missing a using directive or an assembly refrence?)
Please help me
You're trying to call
GetFilesAsync()
on the result of callingGetFolderAsync()
- whereas you should be awaiting the result ofGetFolderAsync()
and then callingGetFilesAsync()
on the result of the await. The return value fromGetFolderAsync()
isn't the folder - it's the asynchronous operation which is fetching the folder. (It's anIAsyncOperation<StorageFolder>
, not aStorageFolder
.)For example: