1. Introduction to Application Data
Applicaion data is equivalent to the registry of a desktop application. It stores user configuration information, such as the running status and user preferences. When you uninstall an application, the data is deleted, therefore, do not store important data.
Applicaion data is not lost even after the application is updated. There is a version control.
Ii. Classification by Purpose
- LocalLocal DataOnly saved on the current device.
- RoamingRoaming dataAll applications of this user installed can be synchronized. Windows will automatically synchronize data to Microsoft's ECs, but it will limit the size. If the user does not use the data (such as program uninstallation) within 30 days, it will be deleted by the server.
- TemporaryTemporary dataData that may be deleted by the system at any time.
Iii. Storage-based classification
APP settings
- It is used to save configuration data, with the deepest 32 layers and unlimited quantity. It can be saved locally and roaming.
- Appsettings supports all winrt data formats except binary. If binary data is stored, files are required.
- The system only verifies the data format and length, and does not verify whether the data is correct.
UseApplicationdata. localsettingsObtain this Static PropertyApplicationdatacontainerClass type configuration.
APP files
- The root directory contains three custom folders: local, roaming, and temporary.
- You can create folders on your own, but there are no more than 32 layers.
Use applicationdata. localfolderThis static property is used to obtainStoragefolderType file.
Iv. Sample Code
Store Local Data
Applicationdatacontainer localsettings = applicationdata. current. localsettings; // store a single configuration handle applicationdatacompositevalue composite = new applicationdatacompositevalue (); // store multiple configuration handles storagefolder localfolder = applicationdata. current. localfolder; // storage file handle
Localsettings. Values ["examplesetting"] = "Hello windows"; // store a single Configuration
Composite ["intval"] = 1;
Composite ["strval"] = "string ";
Localsettings. Values ["examplecompositesetting"] = Composite; // stores multiple configurations
Create a configuration level
ApplicationDataContainer container = localSettings.CreateContainer("exampleContainer", ApplicationDataCreateDisposition.Always);if (localSettings.Containers.ContainsKey("exampleContainer")){ localSettings.Containers["exampleContainer"].Values["exampleSetting"] = "Hello Windows";}
Read Configuration
Object value = localSettings.Values["exampleSetting"];//a settingApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)localSettings.Values["exampleCompositeSetting"];if (composite == null){ // No data}else{ // Access data in composite["intVal"] and composite["strVal"]}bool hasContainer = localSettings.Containers.ContainsKey("exampleContainer");bool hasSetting = false;if (hasContainer){ hasSetting = localSettings.Containers["exampleContainer"].Values.ContainsKey("exampleSetting");}
Delete Configuration
localSettings.Values.Remove("exampleSetting");//ApplicationDataContainerSettings.Remove localSettings.Values.Remove("exampleCompositeSetting");//ApplicationDataCompositeValue.Remove localSettings.DeleteContainer("exampleContainer");//ApplicationDataContainer.DeleteContainer