使用getFilesAsync和getFoldersAsync将文件放入文件夹中

时间:2015-07-13 16:51:05

标签: c# xaml windows-phone runtime

有了这个

public IReadOnlyList<StorageFolder> folderList;

用它做这个

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

我应该将所有文件夹放在Music文件夹中(musicFolder是knownfolders.musiclibrary)

但是当我在cicle内部尝试做

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

我得到了await line系统参数异常..我不明白为什么,我是否正确传递了它?

  

System.ArgumentException:值不在预期范围内。      在Windows.Storage.StorageFolder.GetFilesAsync(CommonFileQuery查询)      在DUS.MainPage.d__31.MoveNext()

1 个答案:

答案 0 :(得分:0)

以这种方式解决: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和SubFolderLib是

public IReadOnlyList<StorageFile> SubFolderlib;

public IReadOnlyList<StorageFolder> FolderLib;