WinRT information: Access is not allowed to the provided path...

Answered WinRT information: Access is not allowed to the provided path...

  • Monday, September 19, 2011 6:13 PM
     
     

    When I run the following code:

    try{

    string sPath = audioFile.Path.Substring(0, audioFile.Path.LastIndexOf("\\") - 1);

    StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(sPath);

    ...

    where sPath is of the form Z:\\Music\.. I get the following exception:

    WinRT information: Access is not allowed to the provided path. The file or folder must exist within an approved location, such as the app storage folders or a capability backed location.

    Z: is a mapped networked drive.

    Can someone please help me understand what this message is saying

    Thank you - David

     

     

     


    David

All Replies

  • Monday, September 19, 2011 6:18 PM
     
     

    Might be because of the winRT actually running applications in a sandboxed mode. Try to execute this code in a normal Windows Form and see if the code executes fine.
    I'm still not sure which things are isolated and which aren't, so I might be wrong here. But I'd guess it's he sandboxing.

    Regards,

    Dylan Meeus


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
  • Monday, September 19, 2011 6:30 PM
     
     

    I am trying to develop a Metro app so I am not sure the 'normal Windows Form' is available. Please correct me if I am wrong in my thinking here.

    Thanks - David


    David
  • Monday, September 19, 2011 6:34 PM
     
     

    It's not, but I suggest you try that code in VisualStudio2010 on that machine so you can see if the problem lies within WinRT or your PC / Code.


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
  • Monday, September 19, 2011 6:46 PM
     
     

    Does the StorageFolder class even exist in VS 2010? I thought it was part of the new Metro api's.

    Thanks...


    David
  • Monday, September 19, 2011 6:47 PM
     
     
    I can't help you any further if the problem lies within WinRT itself, sorry.
    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
  • Monday, September 19, 2011 7:03 PM
     
     Answered

    Because your app is sandboxed, you can only access file locations that are either specifically declared for access in your manifest, or files that the user explicitly grants access to by using the file picker. Anything else is not allowed.

  • Monday, September 19, 2011 7:21 PM
     
     

    Ahh yeah I was right then ^^


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
  • Monday, September 19, 2011 7:47 PM
     
     

    I am still not sure I understand.

    I use the file picker to view a folder on the networked drive to see all the files located in it - so the file picker has no problem accessing any of the folders on the networked drive. I can select one of those files and stream it to MediaPlayer with no problem. I then want to use the folder path of the selected file to return to the same folder using GetFolderFromPathAsync and inumerate the files to find the associated .jpg file.

    Two questions:

    Is my choosing the file using the file picker considered explicitly granting access?

    and

    If the file picker can see the network folders and inumerate the contents why am I unable to?

    Thanks


    David
  • Monday, September 19, 2011 7:53 PM
     
     
    Once you choose a file you have explicitly granted access only to the item that comes back from the picker API. You're trying to open the folder to access other files in the same directory, but the user only chose a single file in the picker. That's the only file the user has granted access to. If you want access to the whole folder, use the FolderPicker.
  • Tuesday, September 20, 2011 8:35 PM
     
     

    I have done more testing after making sure my manifest was setup with the following:

    Home/Work Network, Internet(Client), Music Library, and Removable Storage all checked. Also File Picker was added and all file types allowed.

    I then placed a folder with 15 .mp3's and a 1 .jpg file in the following 4 locations:

    Music Library, C:\users\me\Test, E:\Music\Test, and Y:\Test. C: is the internal hard drive, E: is a USB attached external drive and Y: is a network share that equates to \\myServer\Test.

    I made sure full permission was granted on the folders and all files. I would like to be able to use the file picker to pick a file from the test folder and do two things with it: First, get the folder path the file came from and then second play the file using MediaPlayer. However, before playing the file I want to use the folder path information to enumerate the files to find the .jpg file so as to show the album cover associated with the song playing.

    Here are the results:

    Music Library: Folder found with 16 files, Album cover .jpg retrieved and shown properly and song plays.

    C:\users\me\Test: Folder found with 0 files, Album cover .jpg not retrieved and song plays.

    E:\Music\Test: Folder found with 0 files, Album cover .jpg not retrieved and song plays.

    Y:\Test: Folder not found with exception "WinRT Information: Access is not allowed to provided path... and stream open exception when trying to open .mp3 with same WinRT error and song did not play.

    My question now is...what do I try next? It seems to me I have setup the manifest correctly to allow access to all of the above scenarios, yet only one works correctly.

    I did do one more test. I added the path \\myServer\Test to the Music Library. I was surprised to find that in fact it now accessed both the .jpg and the .mp3. However, when it stands alone outside of the Music Library I can not access either.

    There must be a way for me to get access. It does not make sense that a user will need to insure the network path is added to the Music Library.

    Any support is most appreciated.

    Thanks...


    David
  • Wednesday, September 21, 2011 9:02 PM
     
     

    This behavior is by design. The only locations you can access without explicit user permission are those that your app has defined as a capability. Only library locations can be declared this way. When a user picks a single file from a location to which you don't already have access, you are only granted access to that file, not any others in the same directory. What you can do, however, is allow the user to choose a folder, then you can access all files in that folder. Then you can, for example, show all the songs in a gallery view with album art.

    You may find this video helpful:

    http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-892T

     

     

     

  • Monday, October 24, 2011 12:01 PM
     
      Has Code

    Hi Ari

    Does it mean there is no programming way to access file with arbitrary file path? As  I test, even if I check everything in capabilities, also File Picker was added and all file types allowed, I can still get exception of the following codes:

     

    String fileName = @"C:\Test\dd\ccc.jpg";
    StorageFile file = await StorageFile.GetFileFromPathAsync(fileName);
    

     

    To access such file path,  I must work with File Picker.  Is it possible to read file under any file path in metro style application without using File Picker?

     

    Thanks

    Chang


    • Edited by Chang Chen Monday, October 24, 2011 12:02 PM edit
    •  
  • Monday, October 24, 2011 4:25 PM
    Moderator
     
     

    Does it mean there is no programming way to access file with arbitrary file path?

    Correct.  Metro style apps are sandboxed so they cannot access arbitrary files.  

    --Rob

  • Tuesday, October 25, 2011 2:02 AM
     
     

    Hi 

    why CAN File Picker access arbitrary file path?  And Why can't our metro style application access? Is it by Design? is it possible to open this limitation in the future? or does it need some certification process for accessing arbitrary file path?

     

    thanks

    Chang

  • Tuesday, December 20, 2011 7:50 AM
     
     

    Any chance you can post some of the snippets of your code with the file access and media playing?  I am able to use the FilePicker and MediaPlayer (vs MediaElement) but am having trouble doing the same from a filename stored in a string.  I am referencing a file in the base Music Library, so I believe I should be okay....but it's not working.

    I'm sure a quick glance at how you're opening the files from an arbitrary list/location and I'll smack my head.  Right now, I am in one of those mental blocks.

    Thanks

    Arthur