locked
Regain file acces by FutureAccesList RRS feed

  • Question

  •                 var op = new FileOpenPicker { FileTypeFilter = { "*" }, CommitButtonText = "select this file", SuggestedStartLocation = PickerLocationId.Desktop, ViewMode = PickerViewMode.List };
                    
                    var file = await op.PickSingleFileAsync();
    
                    if (file != null)
                    {
                        StorageApplicationPermissions.FutureAccessList.Add(file);
                    }
                    if (file == null)
                    {
                        StorageFile frmfuture = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(file);
                    }

    This is the code I used to check regain the access to a file. Just a testing code.

    First I select a file and terminate the app.

    And again I want to gain the access to the first selected file without picking the same file again.

    At the second time im not gonna select a file, that means file == null

    Therefore the line below must be run at the second time.

    "StorageFile frmfuture = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(file);"

    But visual studio keep displaying this error..

    "

    Error 1 The best overloaded method match for 'Windows.Storage.AccessCache.StorageItemAccessList.GetFileAsync(string)' has some invalid arguments C:\Users\Astro\documents\visual studio 2013\Projects\MyTutorialFollowings\MyTutorialFollowings\MainPage.xaml.cs 201 51 MyTutorialFollowings"

    Whats the wrong with my code ?

    I know this cant be used in a app because the way I used if condition is not correct. Im just a newbie to Winrt app development. 

    All I wanna know is abaout this line.

    "StorageFile frmfuture = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(file);"

    whats the wrong with this line ?

    • Moved by CoolDadTx Monday, January 13, 2014 3:17 PM WinRT related
    Monday, January 13, 2014 2:31 PM

Answers

  • Hi Astro,
    This is how it works

    string token=StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
    
    StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(token);

    So when adding a file to the future access list you must save token string that you got from adding the file and when retrieve the file use this token to retrieve this file :)

    Regards,


    Ibraheem Osama Mohamed | My Blog | @IbraheemOM | My Website

    (If my reply answers your question, please propose it as an answer)

    • Marked as answer by string Astro Monday, January 13, 2014 4:58 PM
    Monday, January 13, 2014 3:52 PM

All replies

  • file is of type StorageFile as documented by the method since you are storing the return value of the method.

    GetFileAsync requires a string as documented in MSDN.  Since it is already a StorageFile you don't need your second if statement.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Monday, January 13, 2014 3:17 PM
  • so which part of my code is wrong ?
    Monday, January 13, 2014 3:26 PM
  • Remove the last if statement as 'file' is already of type StorageFile which is what you're trying to retrieve.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Monday, January 13, 2014 3:41 PM
  • Hi Astro,
    This is how it works

    string token=StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
    
    StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(token);

    So when adding a file to the future access list you must save token string that you got from adding the file and when retrieve the file use this token to retrieve this file :)

    Regards,


    Ibraheem Osama Mohamed | My Blog | @IbraheemOM | My Website

    (If my reply answers your question, please propose it as an answer)

    • Marked as answer by string Astro Monday, January 13, 2014 4:58 PM
    Monday, January 13, 2014 3:52 PM
  • Thanks.. 
    Monday, January 13, 2014 4:58 PM