locked
Access denied when trying to access file, i just created into applicationData.localFolder

    Question

  • Hi,

    I just downloaded a pdf file with the following code and I see it is in the : C:\Users\<user_name>\AppData\Local\Packages\<package>.LocalState\<My PDF File> folder.

    Now im trying to open this and launch it with Adobe Reader. But VS says this (I named my downloaded pdf file first.pdf):

    0x80070005 - JavaScript runtime error: Access is denied.

    WinRT information: An item cannot be found with the specified name (ms-appdata:///local/first.pdf).

    My code:

                var fileName = "first.pdf";
                var uriString = "https://knome.siilicloud.com/api/bincv/SiiliCV_kari_pirttikangas.pdf?cvid=" + name;
                var download = null;
                var promise = null;
    
    
                var applicationData = Windows.Storage.ApplicationData.current;
                var localFolder = applicationData.localFolder;
    
                    localFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (newFile) {
                    var uri = Windows.Foundation.Uri(uriString);
                    var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
                        
                    // Create a new download operation.
                    download = downloader.createDownload(uri, newFile);
    
                    // Start the download and persist the promise to be able to cancel the download.
                    promise = download.startAsync().then(function complete() {
                        var resultdiv = document.getElementById("result");
                        resultdiv.innerText = "ready!";
    
                        Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("ms-appdata:///local/first.pdf").then(
                          function (file) {
                              // Set the show picker option
                              var options = new Windows.System.LauncherOptions();
                              options.displayApplicationPicker = true;
    
                              // Launch the retrieved file using the selected app
                              Windows.System.Launcher.launchFileAsync(file, options).then(
                                function (success) {
                                    if (success) {
                                        var resultdiv = document.getElementById("result");
                                        resultdiv.innerText = "opening pdf!";
                                    } else {
                                        var resultdiv = document.getElementById("result");
                                        resultdiv.innerText = "error opening pdf!";
                                    }
                                });
                          });
    
                    });
                });
                

    Any help would be great ! thanks!

     

    Yu

    Thursday, July 04, 2013 11:24 AM

Answers

  • Got it.....Should have used

    localFolder.getFileAsync("first.pdf").then

    And Voila....

    • Marked as answer by Yu_Gong Thursday, July 04, 2013 3:32 PM
    Thursday, July 04, 2013 12:28 PM

All replies

  • I tested to open the pdf, and its ok, so at least the download is ok. What do people think about that Url I give to getFileAsync?

    Thursday, July 04, 2013 12:11 PM
  • Got it.....Should have used

    localFolder.getFileAsync("first.pdf").then

    And Voila....

    • Marked as answer by Yu_Gong Thursday, July 04, 2013 3:32 PM
    Thursday, July 04, 2013 12:28 PM