locked
How to copy Package folder of windows 8 app to application data storage

    Question

  • I am creating a functionality to refresh app contents.I tried directly replacing from the package but it just creates a copy. This is what i did. It creates SplashImage-Copy.png. 

    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");
                   });
             
                 
    
          });
     Now I want to copy entire app installed package folder to sandbox or application data storage so that i can add new content to files and reload them again. Please provide a snippet on how to do the copy process.



    • Edited by Ragarock Monday, November 24, 2014 7:50 AM
    Monday, November 24, 2014 7:47 AM

All replies

  • I don't understand this scenario. The only differences your app should have between a new and unused version is information stored in the app data folder.  You should have defaults which never change, and are not deleted, but can be swapped out for different items as needed. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, November 24, 2014 8:28 PM
    Moderator
  • I need to update some specific files and html at runtime when the user wants. My approach is copy the entire package folder to isolated storage and reload my project from there after updating the contents. I would like some help on how to copy the package. I tried this recursive method but it dint work. 
    
    
     var root = Windows.ApplicationModel.Package.current.installedLocation;    copySubDirectories(root);
    
     function copySubDirectories(subFolder) {
           
            currentFolder.createFolderAsync(subFolder.name).done(function (newFolder1) {
               
                    
                  
                        subFolder.getFilesAsync().done(function (fileList1) {
                           
                            if (fileList1==null) {
                                subFolder.getFoldersAsync().done(function (folderList1) {
    
                                    folderList1.forEach(function (subFolder2) {
                                        currentFolder = newFolder1;
                                        copySubDirectories(subFolder2);
                                    });
                                });
                                return;
                            }
                  
                        fileList1.forEach(function (subFile1) {
                         
                            subFile1.copyAsync(newFolder1, subFile1.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function () {
                           
                                subFolder.getFoldersAsync().done(function (folderList1) {
                                  
                                    folderList1.forEach(function (subFolder2) {
                                        currentFolder = newFolder1;
                                        copySubDirectories(subFolder2);
                                    });
                                });
                            });
                        });
                    });
                    
                   
            });
           
    
            }
        
      





    • Edited by Ragarock Thursday, November 27, 2014 4:19 AM
    Thursday, November 27, 2014 4:14 AM