locked
Only the latest file from StorageApplicationPermissions.MostRecentlyUsedList.Entries can be found. RRS feed

  • Question

  • I have looked at the following code again and again,  but am unable to figure out what is wrong: 

    AccessListEntryView mruEntries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
    if (mruEntries.Count > 0)
    {
        foreach (AccessListEntry ale in mruEntries)
        {
            try
            {
                StorageFile sf = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(ale.Token);
                StorageItemThumbnail sit = await sf.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView);
                //more code to use sit
            }
            catch (Exception ex)
            {
                //exception handling code
            }
        }
    }

    No matter how many entries are in  StorageApplicationPermissions.MostRecentlyUsedList.Entries, only the latest used file can be found by StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(ale.Token).  All others generate the following exception:

      "The system cannot find the file specified.\r\n"

    I am wondering if anyone could quickly point out the flaw in the above code.


    Hong

    Wednesday, January 8, 2014 3:20 AM

Answers

  • Your code snippet looks superficially correct and works fine for me in the file access sample (modified to add multiple files to the MRU).

    Did you confirm that the file is still there and the error isn't correct?

    --Rob

    • Marked as answer by Hong (MA, USA) Wednesday, January 8, 2014 12:53 PM
    Wednesday, January 8, 2014 4:17 AM
    Moderator

All replies

  • Your code snippet looks superficially correct and works fine for me in the file access sample (modified to add multiple files to the MRU).

    Did you confirm that the file is still there and the error isn't correct?

    --Rob

    • Marked as answer by Hong (MA, USA) Wednesday, January 8, 2014 12:53 PM
    Wednesday, January 8, 2014 4:17 AM
    Moderator
  • Thanks Rob for looking into this.

    You are right that the older files were not there.  I should have easily checked their locations by examining the instances of StorageFile returned by  StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(ale.Token).

    The culprit is that I misunderstood StorageFile.CopyAsync(IStorageFolder).  I thought this function would return the new copy of file, but the original instance remains the same. It appears that the original instance changes too after calling this method. Here is the old code that led to the exception:

    await myStorageFile.CopyAsync(TempStorageFolder);
    StorageApplicationPermissions.MostRecentlyUsedList.Add(myStorageFile);

    Here is the new code that does not have the problem:

    StorageApplicationPermissions.MostRecentlyUsedList.Add(myStorageFile);
    await myStorageFile.CopyAsync(TempStorageFolder);
    I don't think the MSDN document is clear about the change of the calling instance.  Maybe it just follows certain convention that I do know.  Could you shed some light on this, Rob? 


    Hong

    Wednesday, January 8, 2014 12:18 PM