locked
FilePicker file paths lifetime

    Question

  • When I pick a file or folder's path through file picker in a Windows 8 app, what is the duration for which it is valid (Due to sandboxing restrictions)? For example, If my app does not have permission to access the document library and I choose a file from document library through file picker. Now, If I save this path in my app settings and try to use it after app is launched again (after termination), will it be still valid? If not, is there a way to make it usable across application launches once I get its access through file picker?
    Wednesday, November 28, 2012 8:56 AM

Answers

  • You should use the StorageFile directly and never try to access the file by path. The FilePicker is not limited to file system objects and may return StorageFiles without paths. The app will not have access to reopen paths in restricted locations.

    You can cache the StorageFile for later access with the Windows.Storage.AccessCache functions. This will allow reopening a StorageFile retrieved through a FilePicker in a later instance of the app. See How to track recently used files and folders for more explanation and links to samples.

    --Rob

    Friday, November 30, 2012 7:19 AM
    Owner

All replies

  • Hi,

    Generally speaking, after we select a file from filePicker, it will be store in the IStorageFile. If the App suspend or close, the IStorageFIle object will  delete by system. So that we cannot open it again.

    If we store the file with the name like Document\test.txt. But we can not open the file directly from the path. We need get the KnowFolder::Document first and then open the file with its name. In this way, we need the permission to access the document.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 29, 2012 5:58 AM
  • With Mac OS we have a concept of security scoped bookmarks which provides persistent access to files across app launches. Initial access is obtained through file picker and then it can be bookmarked for later use.

    Don't we have a similar functionality for windows 8 apps? Then, what is the recommendation for photo browsing applications which want to allow the browsing of photographs outside app's sandbox?

    Thursday, November 29, 2012 6:28 AM
  • Hi,

    I think you can try the Cached File Updater contract.
    Please check the "Test the services provided by your app from a file picker that is called by another app" section
    http://msdn.microsoft.com/library/windows/apps/Hh465192

    Sample codes:
    File picker contracts sample
    http://code.msdn.microsoft.com/windowsapps/File-picker-app-extension-0cb95155
    File picker sample
    http://code.msdn.microsoft.com/windowsapps/File-picker-sample-9f294cba/
     
    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 29, 2012 8:05 AM
  • You should use the StorageFile directly and never try to access the file by path. The FilePicker is not limited to file system objects and may return StorageFiles without paths. The app will not have access to reopen paths in restricted locations.

    You can cache the StorageFile for later access with the Windows.Storage.AccessCache functions. This will allow reopening a StorageFile retrieved through a FilePicker in a later instance of the app. See How to track recently used files and folders for more explanation and links to samples.

    --Rob

    Friday, November 30, 2012 7:19 AM
    Owner
  • Thanks Rob,

    If I use FutureAccessList and insert a file/folder there, will it consume my disk space? If I insert 5 files of 100MB is each, does it mean that it will end up eating 500MB of disk space? Or it just stores the file's metadata there?

    And what happens on app update? When an app is updated will my FutureAccessList continue to work?


    • Edited by John Rick Friday, November 30, 2012 7:28 AM
    Friday, November 30, 2012 7:27 AM
  • The access is cached, not the file itself. It won't take significant disk space, and if the original file is removed then the app won't be able to load it.

    This should survive an app update, but not an app uninstall.

    --Rob

    Saturday, December 01, 2012 2:47 AM
    Owner