Javascript 如何在Windows应用商店/WinJS应用程序中处理文件激活

Javascript 如何在Windows应用商店/WinJS应用程序中处理文件激活,javascript,windows-store-apps,winjs,Javascript,Windows Store Apps,Winjs,我正在尝试让我的文本编辑器应用程序处理文件启动。Microsoft在此提供了一个如何执行此操作的示例: 不幸的是,它在接收文件时停止,并且没有给出关于如何实际打开该文件的任何信息 我可以成功地处理激活的事件,并最终获得文件的绝对路径。比如说, C:\Users\Rory\Documents\test.txt Metro应用程序没有访问绝对路径的权限,除非在某些条件下 如果用户通过文件选择器选择文件 如果应用程序以前访问过该文件,并且路径已存储在Windows.Storage.AccessCa

我正在尝试让我的文本编辑器应用程序处理文件启动。Microsoft在此提供了一个如何执行此操作的示例:

不幸的是,它在接收文件时停止,并且没有给出关于如何实际打开该文件的任何信息

我可以成功地处理激活的事件,并最终获得文件的绝对路径。比如说,

C:\Users\Rory\Documents\test.txt
Metro应用程序没有访问绝对路径的权限,除非在某些条件下

  • 如果用户通过文件选择器选择文件
  • 如果应用程序以前访问过该文件,并且路径已存储在Windows.Storage.AccessCache中
  • 如果应用程序作为启动传递文件。
  • 即使数字3适用于这种情况,我也无法打开该文件

    我尝试了
    Windows.Storage.StorageFile.getFileFromPathAsync(path\u to\u file)
    ,但出现了此错误

    0x80070005 - JavaScript runtime error: Access is denied.
    
    WinRT information: Cannot access the specified file or folder (඀6). 
    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.
    

    我已经将我的应用程序包清单设置为接受txt文件

    WebUIFileActivatedEventArgs
    参数中将
    StorageFile
    StorageFile
    传递给您的应用程序。试试这个:

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.file) {
            if (args.detail.files.size > 0) {
                var storageFile = args.detail.files[0];
                Windows.Storage.FileIO.readTextAsync(storageFile).then(function (text) {
                    // Do something with the content of the file.
                });
            }
        }
    
        // ...
    }