Search code examples
javascriptwindows-8windows-runtimewinjswindows-store

WinRT Acces denied to file


I am having this weird problem. I have an app that can create playlists with this code

var playlist = new Windows.Media.Playlists.Playlist();  
...
WinJS.Utilities.id("appbar-save-button").listen("click", function ()
        {
            var savePicker = new Windows.Storage.Pickers.FolderPicker();
            savePicker.fileTypeFilter.append("*");

            savePicker.pickSingleFolderAsync().then(function (folder)
            {
                playlist.saveAsAsync(folder, "My Playlist", Windows.Storage.NameCollisionOption.replaceExisting, Windows.Media.Playlists.PlaylistFormat.windowsMedia);
            });

        })

The problem comes when I try to acces this file with this code

WinJS.Utilities.id("appbar-open-button").listen("click", function ()
        {
            var openPicker = Windows.Storage.Pickers.FileOpenPicker();

            openPicker.fileTypeFilter.append(".wpl");
            openPicker.pickSingleFileAsync().then(function (file)
            {
                Windows.Media.Playlists.Playlist.loadAsync(file).then(function (playlist)
                {
                    // Print the name of the playlist.
                });
            });

        })

On the commented line I get an exception : Cannot access the specified file or folder (⑰ᑲÕ). The item is not in a location that the application has access to (including application data folders, folders that are accessible via capabilities, and persisted items in the StorageApplicationPermissions lists). Verify that the file is not marked with system or hidden file attributes.

I have given the application Document library capabilities with File Type associations with type .wpl but still I get this exception. How can I fix it

EDIT: Adding the videos to the future acces list seems to solve the problem for app created playlists, but for random playlists the problem persists.


Solution

  • As far as i can see, the issue is not with the permission to load the 'playlist' file; using the file picker if a file is selected at any location on the computer, user will get access to the file; same applies to the folder picker where access to all files in the folder will be there. After that, if the selected file/folder is added to the FutureAccessList, the folder/file will be accessible later also.

    The playlist may be containing files that are in the folders not accessible to user. To confirm this, try to open a playlist with no files or files in the music library location only - after giving the application 'music library' capability. If this works - application need to have settings to add folders with the music. playlist that will contain files in the selected folders will only load.