locked
Settings Form, storing form, and recalling data

    Question

  • Are there any good MSDN examples of this? The only ones that I have found on data storage haven't been too helpful.

    Can someone give me some help with this?

    I'd like to have the user input some text fields, and then the app would store that information, and display that information on the main default.html page.

    Wednesday, November 07, 2012 11:00 PM

Answers

  • Hi,

    I will provide two methods to store data.

    First:

    (function () {  
        "Use Strict";  
      
        var localSettings = Windows.Storage.ApplicationData.current.localSettings;  
      
        function loadLocalSettingData(key) {  
            var txt = localSettings.values[key];  
      
            console.log("loadLocalSettingData('" + key + "')");  
            var data = JSON.parse(txt);  
      
            return data;  
        }  
      
        function saveLocalSettingData(key, data) {  
      
            var txt = JSON.stringify(data);  
      
            localSettings.values[key] = txt;  
      
            console.log("saveLocalSettingData('" + key + "')");  
        }  
      
          
        WinJS.Namespace.define("LocalAppStorage", {  
            loadLocalSetting: loadLocalSettingData,  
            saveLocalSetting: saveLocalSettingData  
        });  
      
    })(); 

    Second:

    //var jsonText = JSON.stringify(activitiesArray)
        var jsonText="hey, I am transfered";
    
        var localFolder = Windows.Storage.ApplicationData.current.localFolder;
        //localFolder.createFileAsync("myfile.data", Windows.Storage.CreationCollisionOption.replaceExisting)
        //    .then(function (file) {
        //        return Windows.Storage.FileIO.writeTextAsync(file, jsonText);
        //    });
    
    
        localFolder.getFileAsync("myfile.data")
                        .then(function (file) {
                            return Windows.Storage.FileIO.readTextAsync(file);
                        }).done(function (text) {
                            // activitiesArray = JSON.parse(text);
                            document.getElementById("content").innerHTML=text;
                        });


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Tuesday, November 13, 2012 7:00 AM
    Thursday, November 08, 2012 7:35 AM

All replies

  • Hi,

    I will provide two methods to store data.

    First:

    (function () {  
        "Use Strict";  
      
        var localSettings = Windows.Storage.ApplicationData.current.localSettings;  
      
        function loadLocalSettingData(key) {  
            var txt = localSettings.values[key];  
      
            console.log("loadLocalSettingData('" + key + "')");  
            var data = JSON.parse(txt);  
      
            return data;  
        }  
      
        function saveLocalSettingData(key, data) {  
      
            var txt = JSON.stringify(data);  
      
            localSettings.values[key] = txt;  
      
            console.log("saveLocalSettingData('" + key + "')");  
        }  
      
          
        WinJS.Namespace.define("LocalAppStorage", {  
            loadLocalSetting: loadLocalSettingData,  
            saveLocalSetting: saveLocalSettingData  
        });  
      
    })(); 

    Second:

    //var jsonText = JSON.stringify(activitiesArray)
        var jsonText="hey, I am transfered";
    
        var localFolder = Windows.Storage.ApplicationData.current.localFolder;
        //localFolder.createFileAsync("myfile.data", Windows.Storage.CreationCollisionOption.replaceExisting)
        //    .then(function (file) {
        //        return Windows.Storage.FileIO.writeTextAsync(file, jsonText);
        //    });
    
    
        localFolder.getFileAsync("myfile.data")
                        .then(function (file) {
                            return Windows.Storage.FileIO.readTextAsync(file);
                        }).done(function (text) {
                            // activitiesArray = JSON.parse(text);
                            document.getElementById("content").innerHTML=text;
                        });


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Tuesday, November 13, 2012 7:00 AM
    Thursday, November 08, 2012 7:35 AM
  • Hi,

    I will provide two methods to store data.

    First:

    (function () {  
        "Use Strict";  
      
        var localSettings = Windows.Storage.ApplicationData.current.localSettings;  
      
        function loadLocalSettingData(key) {  
            var txt = localSettings.values[key];  
      
            console.log("loadLocalSettingData('" + key + "')");  
            var data = JSON.parse(txt);  
      
            return data;  
        }  
      
        function saveLocalSettingData(key, data) {  
      
            var txt = JSON.stringify(data);  
      
            localSettings.values[key] = txt;  
      
            console.log("saveLocalSettingData('" + key + "')");  
        }  
      
          
        WinJS.Namespace.define("LocalAppStorage", {  
            loadLocalSetting: loadLocalSettingData,  
            saveLocalSetting: saveLocalSettingData  
        });  
      
    })(); 

    Second:

    //var jsonText = JSON.stringify(activitiesArray)
        var jsonText="hey, I am transfered";
    
        var localFolder = Windows.Storage.ApplicationData.current.localFolder;
        //localFolder.createFileAsync("myfile.data", Windows.Storage.CreationCollisionOption.replaceExisting)
        //    .then(function (file) {
        //        return Windows.Storage.FileIO.writeTextAsync(file, jsonText);
        //    });
    
    
        localFolder.getFileAsync("myfile.data")
                        .then(function (file) {
                            return Windows.Storage.FileIO.readTextAsync(file);
                        }).done(function (text) {
                            // activitiesArray = JSON.parse(text);
                            document.getElementById("content").innerHTML=text;
                        });


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    I understand how to store data, but I'm not sure how to do so with a settings form (with text input fields)
    Thursday, November 08, 2012 3:04 PM