Search code examples
javascriptwindows-phone-8windows-runtimewindows-store-appswinjs

Refresh App contents Dynamically for Windows Store App


I am trying to replace/update some files in my app package. I tried this code but all it does is create a copy. If i try to replace a file icon.png, the file get copied as icon- copy.png. Is there a way i can actually replace the original file.

Windows.Storage.ApplicationData.current.localFolder.getFileAsync("SplashImage.png")
.done(function (sourcefile) {
  var root = Windows.ApplicationModel.Package.current.installedLocation.path;
  var path = root + "\\images";
  var StorageFolder = Windows.Storage.StorageFolder;
  var folderPromise = StorageFolder.getFolderFromPathAsync(path);
  folderPromise.done(function (folder) {
      sourcefile.copyAsync(folder,"SplashImage.png", Windows.Storage.NameCollisionOption.ReplaceExisting).done(function(result){


           Windows.System.Launcher.launchFileAsync(result).done(function () {
               alert("success");
           });



  });


      });


  });

Solution

  • Package contents are read-only, so you cannot replace them at runtime. A general strategy is to copy the package file to your local storage, and reference the image from there using ms-appdata:///local/ URIs (remember to create an instance of Windows.Foundation.Uri when necessary--check the API you're using). Then you can replace that file any time.

    It looks from your code that you're wanting to replace the splash screen image for the app. This can be done only by updating the app package in the Store, because that image is there to guarantee that something displays for the app even if none of its code ever executes.

    To customize the splash screen, you use an "extended splash screen" which means making the first page of your app initially look like the default screen, and then transitioning to whatever customizations you want. I cover the details of this in my free ebook, Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition, in Appendix B.