locked
KnownFolders.PicturesLibrary.GetFilesAsync() function can not get files after restart the Surface device RRS feed

  • Question

  • We found the KnownFolders.PicturesLibrary.GetFilesAsync() function can NOT work in serval minutes after restart Surface device.

    1) There is no any picature locate at Library Pictures folder;

    2) Restart the Surface device, Run the "Camera" application and take a photo, then exit "Camera" application;

    3) Now we found the photo locate at Library Pictures Camera Roll folder;

    4) We call KnownFolders.PicturesLibrary.GetFilesAsync() function to emulate all files, the Completed event return the IReadOnlyList<StorageFile> file list, but there is no any file in the list.  and GetFilesAsync() function invoke is successful, it don't throw any excetpion.

    5) waiting serval minutes, re-call GetFileAsync() again, then IReadOnlyList<StorageFile> will return one file;

    6) Now the GetFileAsync() always can work fine.

    We can reproduce this issue in Microsoft Surface device, but can NOT reproduce it in PC.  So dose it a file system issue in Surface device?

    This issue only can be reproduced during serval minutes after restart Surface device.  If we don't restart the Surface device, this function can work fine.


    • Edited by LuXiaoHua Monday, September 16, 2013 11:05 AM
    Monday, September 16, 2013 11:02 AM

Answers

  • Hi,

    The issue of using the parameterless GetFilesAsync() API and the API returning 0 files is a known issue with the indexer. To workaround this issue, you can use the following code that prevents using the Indexer:

                try
                {
                    QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, null)
                    {
                        IndexerOption = IndexerOption.DoNotUseIndexer,
                        FolderDepth = FolderDepth.Deep,
                    };
                    StorageFileQueryResult queryResult = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
    
                    IReadOnlyCollection<StorageFile> files = await queryResult.GetFilesAsync(0,10000);
                    // files.Count should now be greater than 0;
                }
                catch (Exception oEx)
                {
                    // handle the exception
                }


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Monday, September 23, 2013 5:03 PM
    Moderator

All replies

  • I cannot reproduce the issue with the above steps. There are however a few things to be clarified here:

    You seem to be calling the GetFilesAsync() which will ONLY return files that are present in the top level folder (not child folders). So, if you delete all pictures in the Pictures folder and then use the Camera app to create an image in the Camera Roll folder, the picture gets created in the CameraRoll folder (not Pictures). When you call GetFilesAsync now, it will still return 0 files because there are pictures in the "Camera Roll" folder not in "Pictures"

    There is another overloaded function called GetFilesAsync(CommonFileQuery). If I use the CommonFileQuery.OrderByName, then I get the desired result indicating that 1 file is present - under "Camera Roll".


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Monday, September 16, 2013 11:58 PM
    Moderator
  • Hi,

         following is my code, we scan the whole folder(include child folders) in our code.

         we I  can reporoduce this issue in Microsoft Surface device after restart device.

         Ater restart device and waiting 5 minutes, the issue can NOT be reproduced, and we also can NOT reproduced this issue in PC machine.

                try
                {
                    m_asyncScan = KnownFolders.PicturesLibrary.GetFilesAsync(CommonFileQuery.OrderByDate, 0, 10000);
                    m_asyncScan.Completed = (IAsyncOperation<IReadOnlyList<StorageFile>> asyncInfo, AsyncStatus asyncStatus) =>
                    {
                        if (asyncInfo.Status == AsyncStatus.Completed)
                        {
                            IReadOnlyList<StorageFile> resultList = asyncInfo.GetResults();
                            m_foundFileList = new List<StorageFile>(resultList);
                            m_asyncScan = null;

                            m_asyncNotify = m_dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {

                                if (m_foundFileList.Count <= 0)  // finished updated scanning
                                {
                                     // pop up info to alert no files
                                }
                                else
                                {
                                       // do other things
                                }
                            });
                        }
                    };

                }
                catch (System.Exception eException)
                {
                     // pop up error message
                }


    • Edited by LuXiaoHua Tuesday, September 17, 2013 6:57 AM
    Tuesday, September 17, 2013 6:55 AM
  • Hello,

    Yes, I am able to reproduce your issue on Surface RT. Let me check with the owners of that area and get back to you.

    Here are the repro steps I followed:

    • Delete all the files in the Pictures folder
    • Restart Surface RT
    • Run the app, it will show 0 files present in the Pictures folder (this is expected)
    • If you use the Camera app to take a picture, a picture will be saved in the “Camera Roll” folder under Pictures.
    • If you run the same app, the app reports zero files found, but there is one file present.
    • This issue goes away if the app is re-run (or GetFilesAsync is queried again) after let’s say 5 minutes, where the app reports 1 file found.

    Thanks,

    Prashant


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Wednesday, September 18, 2013 12:08 AM
    Moderator
  • Most likely this is happening because of indexing. All known folders are indexed automatically and when you use CommonFileQuery.OrderByDate option for the GetFilesAsync, the index is used for the search, not the actual folder structure.

    Try to repeat the test with CommonFileQuery.DefaultQuery - it will ignore the index and if I am correct should return the right number of files.


    Blog: http://lunarfrog.com/blog

    Wednesday, September 18, 2013 10:47 AM
  • Okay, I will try it with CommonFileQuery.DefautQuery, then sort all the file list by myself.
    Saturday, September 21, 2013 10:48 AM
  • Hi,

    The issue of using the parameterless GetFilesAsync() API and the API returning 0 files is a known issue with the indexer. To workaround this issue, you can use the following code that prevents using the Indexer:

                try
                {
                    QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, null)
                    {
                        IndexerOption = IndexerOption.DoNotUseIndexer,
                        FolderDepth = FolderDepth.Deep,
                    };
                    StorageFileQueryResult queryResult = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
    
                    IReadOnlyCollection<StorageFile> files = await queryResult.GetFilesAsync(0,10000);
                    // files.Count should now be greater than 0;
                }
                catch (Exception oEx)
                {
                    // handle the exception
                }


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Monday, September 23, 2013 5:03 PM
    Moderator
  • When can we expect a fix for this? That is to say, are we waiting for the next Windows release or will bug fixes be addressed in a more timely manner?

    I ask because the number of 'known issues' I'm having to work around is piling up and I'm starting to wonder if writing a Windows Store App is a poor use of my time. If bug fixes were pushed out monthly, then that would serve as proof that Microsoft was serious about making something out of the Windows Store.

    Friday, November 22, 2013 6:52 PM
  • Using IndexerOption.DoNotUserIndexer does not solve the problem for me. In my particular scenario, my app is running in a highly locked-down version of Windows 8.1 (with update 1).  There must be some setting in the OS that affects whether or not this works as expected. I have verified WSearch service is running, but that shouldn't matter if I specify in the QueryOptions not to use the indexer.

    I want to simply output the name of all files in a directory of my app. Is there any other way to do that? This method does not work.

    If not, is there a fix for this or any other documented workaround?

    Tuesday, November 4, 2014 2:32 AM