locked
How to get storagefolder by any path

    Question

  • hi, all

        I want to use file access system in metro. Now I can use knownFolder to get a storageFolder, but how can I get a storageFolder by any path?

      Example, the path is: d:\test . How do I get a storageFolder by (d:\test)?

    Thank you for your help.

    Wednesday, June 6, 2012 11:14 AM

Answers

All replies

  • Hi,

    Metro apps run in sandboxed mode, so you can only access :-

    1) File locations that are either specifically declared for access in your manifest ,

    2) Files that the user explicitly grants access to by using the file picker.

    More information - http://social.msdn.microsoft.com/Forums/pl/winappswithcsharp/thread/46a3088d-8420-485b-8697-8b2dda0f1f19

    StorageFolder class - http://msdn.microsoft.com/en-US/library/windows/apps/windows.storage.storagefolder

    I hope that helps,

    Sagar



    Thursday, June 7, 2012 12:40 AM
    Moderator
  • Hi, Sagar

          Does it mean there is no way to acccess arbitrary file path except using file picker? Is it a design?  

          How to declare file locatoin in the manifest?

    Thursday, June 7, 2012 12:59 AM
  • Correct: there is no way to access arbitrary file paths.

    Metro style apps have direct access only to their installed location and application data folders. To access files elsewhere they rely on a broker process to read the file and provide the information back to them via a StorageFolder or StorageFile object. This broker will access only libraries declared via the capabilities or locations selected explicitly by the user via the FileOpenPicker and its like.

    There is no way to get direct access to files elsewhere in the system and no way to get a StorageFolder to non-library locations (such as d:\test) without the user choosing it for you.

    See App capability declarations for information on how to request the capability to read library locations in your app manifest.

    --Rob

    Thursday, June 7, 2012 2:06 AM
    Owner
  • You can ask user to pick a folder when first time run and then use FutureAccessList to store that folder for a future use (you can use even after application restart).

    Thursday, June 7, 2012 8:37 AM