Get settings and file containers for your app
Use the applicationdata.localsettings property to get the settings in the Applicationdatacontainer object. Use the Applicationdata.localfolder property to get the files in the Storagefolder object.
Here is a helper class for the corresponding data manipulation in my package, mainly around the above two APIs:
Public classAppdatahelper {#regionField/// <summary> ///get the app's settings container/// </summary> Private StaticWindows.Storage.ApplicationDataContainer localsettings =Windows.Storage.ApplicationData.Current.LocalSettings; /// <summary> ///get isolated Storage files/// </summary> Private StaticWindows.Storage.StorageFolder Localfolder =Windows.Storage.ApplicationData.Current.LocalFolder; #endregion #regionSet application settings (simple settings, composite settings, settings in the container)/// <summary> ///Simple Setup/// </summary> /// <param name= "key" ></param> /// <param name= "value" ></param> Public Static voidSetValue (stringKeystringvalue) {Localsettings.values[key]=value; } /// <summary> ///Composite Settings/// </summary> /// <param name= "composite" ></param> Public Static voidSetcompositevalue (Windows.Storage.ApplicationDataCompositeValue composite) {composite["intval"] =1; composite["Strval"] ="string"; localsettings.values["examplecompositesetting"] =Composite; } /// <summary> ///Create a settings container/// </summary> /// <param name= "ContainerName" ></param> /// <returns></returns> Private StaticWindows.Storage.ApplicationDataContainer CreateContainer (stringcontainername) { returnLocalsettings.createcontainer (ContainerName, Windows.Storage.ApplicationDataCreateDisposition.Always); } /// <summary> ///Speaking settings save to Settings container/// </summary> /// <param name= "ContainerName" ></param> /// <param name= "key" ></param> /// <param name= "value" ></param> Public Static voidSetcontainervalue (stringContainerName,stringKeystringvalue) { if(!LocalSettings.Containers.ContainsKey (containername)) CreateContainer (containername); Localsettings.containers[containername]. Values[key]=value; } #endregion #regionGet app settings (simple settings, composite settings, settings in the container)/// <summary> ///Get app Settings/// </summary> /// <param name= "key" ></param> /// <returns></returns> Public Static ObjectGetValue (stringkey) { returnLocalsettings.values[key]; } /// <summary> ///Get composite Settings/// </summary> /// <param name= "Compositekey" ></param> /// <returns></returns> Public StaticWindows.Storage.ApplicationDataCompositeValue Getcompositevalue (stringCompositekey) { //Composite SettingWindows.Storage.ApplicationDataCompositeValue composite =(Windows.Storage.ApplicationDataCompositeValue) Localsettings.values[compositekey]; returnComposite; } /// <summary> ///get app settings from the settings container/// </summary> /// <returns></returns> Public Static ObjectGetvaluebycontainer (stringContainerName,stringkey) { BOOLHascontainer =LocalSettings.Containers.ContainsKey (containername); if(hascontainer) {returnLocalsettings.containers[containername]. Values.containskey (key); } return NULL; } #endregion #regionRemove the settings that have been completed/// <summary> ///remove simple settings or composite settings/// </summary> /// <param name= "key" ></param> Public Static voidRemove (stringkey) {LocalSettings.Values.Remove (key); } /// <summary> ///Delete Settings Container/// </summary> /// <param name= "key" ></param> Public Static voidRemovecontainer (stringcontainername) {Localsettings.deletecontainer (containername); } #endregion #regionFile Store Operations/// <summary> ///Write File/// </summary> Public Async voidWritetimestamp (stringFileName,stringcontents) { Try{Windows.Storage.StorageFile Samplefile=awaitLocalfolder.createfileasync (FileName, Windows.Storage.CreationCollisionOption.ReplaceExisting); awaitWindows.Storage.FileIO.WriteTextAsync (samplefile, contents); } Catch(Exception) {Throw; } } /// <summary> ///Read File/// </summary> Public Asynctask<string> Readtimestamp (stringfileName) { Try{Windows.Storage.StorageFile Samplefile=awaitLocalfolder.getfileasync (fileName); stringContents =awaitWindows.Storage.FileIO.ReadTextAsync (Samplefile); returncontents; } Catch(Exception) {return "Read Faild"; } } #endregion }
UWP: Local app data