2013-11-22 200 views
0

我一直在运行教程并构建基本的Windows 8.1商店应用程序。 应用程序通过对,我已经存储在资产文件夹,并一直试图让他们在默认情况下,窗口阅读器打开PDF文件containes各个环节......在Windows 8.1商店应用程序中打开各种pdfs

到目前为止,我有打开一次完美的一个pdf文件点击。但是我需要这个工作来处理所有的PDF文件,而不仅仅是我在filetoLaunch变量中指定的文件。

(function() { 
"use strict"; 

WinJS.UI.Pages.define("/pages/page/page.html", { 

    ready: function (element, options) { 
     document.getElementById("file").addEventListener("click", launchFile, false); 

    } 
}); 

var fileToLaunch = "assets\\mypdf.pdf"; 

function launchFile() { Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(fileToLaunch).done(
     function (file) { 
      Windows.System.Launcher.launchFileAsync(file).done(
       function (success) { 
        if (success) { 
         WinJS.log && WinJS.log("File " + file.name + " launched.", "sample", "status"); 
        } else { 
         WinJS.log && WinJS.log("File launch failed.", "sample", "error"); 
        } 
       }); 
     }); 
} 

基本上我无法弄清楚如何改变filetoLaunch变量定义所有的PDF文件,而不仅仅是一个单一的一个。

任何想法都会很棒!谢谢。

回答

0

只需在该函数中传递您的文件名即可。

你只需要给完整的文件路径。

HTML

<button onclick="fileLauncher('Database.txt')">Database.txt</button> 
<button onclick="fileLauncher('Modules.txt')">Modules.txt</button> 
<button onclick="fileLauncher('My_Comments.pdf')">My_Comments.pdf</button> 

JS

function fileLauncher(fileName) { 

    var fileToLaunch = "Assets\\"+fileName; 

    Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(fileToLaunch).done(
      function (file) { 
       Windows.System.Launcher.launchFileAsync(file).done(
        function (success) { 
         if (success) { 
          WinJS.log && WinJS.log("File " + file.name + " launched.", "sample", "status"); 
         } else { 
          WinJS.log && WinJS.log("File launch failed.", "sample", "error"); 
         } 
        }); 
      }); 

} 
相关问题