Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果使用getFileAsync而不是Picker.pickSingleFileAsync,则无法从FutureAccessList检索文件_C#_Javascript_Windows_Windows Store Apps - Fatal编程技术网

C# 如果使用getFileAsync而不是Picker.pickSingleFileAsync,则无法从FutureAccessList检索文件

C# 如果使用getFileAsync而不是Picker.pickSingleFileAsync,则无法从FutureAccessList检索文件,c#,javascript,windows,windows-store-apps,C#,Javascript,Windows,Windows Store Apps,我有一个应用程序可以通过两种方式检索文件:一种是使用文件选择器,另一种是直接使用路径。在这两种情况下,我都会获取文件,将其添加到未来访问列表中,并将令牌保存在一个数组中。稍后在应用程序中,我使用令牌使用futureAccessList.getFileAsync检索文件。现在,第二部分,即使用令牌代码返回文件在这两种情况下是相同的,因此它必须以我将其添加到未来访问列表的方式进行,因为它在我使用filepicker时有效,但在我直接使用路径时无效 文件选择器添加代码 // Create th

我有一个应用程序可以通过两种方式检索文件:一种是使用文件选择器,另一种是直接使用路径。在这两种情况下,我都会获取文件,将其添加到未来访问列表中,并将令牌保存在一个数组中。稍后在应用程序中,我使用令牌使用
futureAccessList.getFileAsync
检索文件。现在,第二部分,即使用令牌代码返回文件在这两种情况下是相同的,因此它必须以我将其添加到未来访问列表的方式进行,因为它在我使用filepicker时有效,但在我直接使用路径时无效

文件选择器添加代码

    // Create the picker object and set options
    var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
    openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;

    // Select MIDI files only
    openPicker.fileTypeFilter.replaceAll([".mp3"]);

    // Open the picker for the user to pick a file
    openPicker.pickSingleFileAsync().then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name, "sample", "status");

            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);

            // Save the file mapping. If it exists, overwrite.
            fileMappings[padId] = { padNumber: padId, audioFile: listToken };
        }
        else {
            // The picker was dismissed with no selected file
            WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
        }
    });
    Windows.Storage.KnownFolders.musicLibrary.getFileAsync("filename.mp3").then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name + ", full path: " + file.path, "sample", "status");

            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);

            // Save the file mapping. If it exists, overwrite.
            fileMappings['pad0'] = { padNumber: 'pad0', audioFile: listToken };
        }
        else {
            // Could not get access to the file
            WinJS.log && WinJS.log("File unavailable!", "sample", "status");
        }
    });
直接路径添加代码

    // Create the picker object and set options
    var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
    openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;

    // Select MIDI files only
    openPicker.fileTypeFilter.replaceAll([".mp3"]);

    // Open the picker for the user to pick a file
    openPicker.pickSingleFileAsync().then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name, "sample", "status");

            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);

            // Save the file mapping. If it exists, overwrite.
            fileMappings[padId] = { padNumber: padId, audioFile: listToken };
        }
        else {
            // The picker was dismissed with no selected file
            WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
        }
    });
    Windows.Storage.KnownFolders.musicLibrary.getFileAsync("filename.mp3").then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name + ", full path: " + file.path, "sample", "status");

            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);

            // Save the file mapping. If it exists, overwrite.
            fileMappings['pad0'] = { padNumber: 'pad0', audioFile: listToken };
        }
        else {
            // Could not get access to the file
            WinJS.log && WinJS.log("File unavailable!", "sample", "status");
        }
    });
就我个人而言,我觉得这一行
(Windows.Storage.KnownFolders.musicLibrary.getFileAsync)
并没有给我读写权限,只是读取,这可能是造成混乱的原因。这是。这是一个C#MediaElement问题,但密切相关。你知道这里有什么问题吗?如果它与权限相关,我如何指定我需要r-w访问权限?我认为在appxmanifest中指定功能已经足够好了。如果有人需要,我可以在这里添加文件检索代码。谢谢你抽出时间


[使用Javascript的Windows RT应用程序。已检查确认的“音乐库”功能。]

您的代码是正确的。这是WinRT API中的一个错误。我在系统的那个部分工作,并在这个主题上提出了一个bug

我看不出有什么问题:(但为什么你说你需要rw访问该文件…你不是在这里读取吗?我想我不需要读写访问,但我猜这就是问题所在。存储文件通常不控制读写访问。它不代表打开的文件句柄。当你打开随机访问流时,你需要指定通知您想要的访问权限。在某些情况下,当文件作为共享合同的一部分传递给应用程序时,存储文件确实会限制访问权限。请链接以连接问题/错误报告?即,您说您“提交了错误”,但在何处?是否确实存在错误?MS是否确认了这一点?