Search code examples
c#xamlwindows-phoneruntime

Get File inside a folder with getFilesAsync and getFoldersAsync


Having this

public IReadOnlyList<StorageFolder> folderList;

and do this with it

folderList = await musicFolder.GetFoldersAsync(CommonFolderQuery.GroupByAlbum);

I should have all folders inside Music folder (musicFolder is knownfolders.musiclibrary)

but when inside a cicle i try to do

for (int i=0; i<folderList.Count; i++)
                    {
                        if (folderList[i].Name==(lbMusic_Albums.SelectedItem as songStruct).songName)
                        {

                            StorageFolder current = folderList[i];

                            IReadOnlyList<StorageFile> TempFileList = await current.GetFilesAsync(CommonFileQuery.OrderByName); //OTHER CODE

I get on the await line system argument exception.. I do not understand why, Am i passing it correctly?

System.ArgumentException: Value does not fall within the expected range. at Windows.Storage.StorageFolder.GetFilesAsync(CommonFileQuery query) at DUS.MainPage.d__31.MoveNext()


Solution

  • Solved in this way :D

    FolderLib = await musicFolder.GetFoldersAsync(CommonFolderQuery.GroupByAlbum);
    //Obtaining all the folders and do for every folder this
    
    
     foreach(StorageFolder item in FolderLib)
     {  // Take the subfolder
         SubFolderlib = await item.GetFilesAsync();
        // and do stuff with it
     }
    

    FolderLib and SubFolderLib were

    public IReadOnlyList<StorageFile> SubFolderlib;
    
    public IReadOnlyList<StorageFolder> FolderLib;