Develop application data in Windows 8

Source: Internet
Author: User

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 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.