"Reprint" UWP app settings and file settings: Science

Source: Internet
Author: User

Data has two basic classification, application data and user data, and user data is user-owned data, such as documents, music or e-mail, etc., the following will be a general introduction to the basic operation of the application data.

App data: App data contains app status information (such as runtime status, user settings, etc.), including settings and files, app data has its own storage area when the application is installed, and is emptied when uninstalled

    • Settings: Store user preferences and application state to store multiple data types
      • UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, single, Double
      • Boolean
      • Char16 and String
      • DateTime and TimeSpan
      • GUID, point, Size, Rect
      • Applicationdatacompositevalue: A set of related application settings that must be serialized and deserialized atomically. Use composite settings to easily handle atomic updates of interdependent settings. The system ensures the integrity of the composite settings when concurrent access and roaming. Composite settings are optimized for a small amount of data, and can be poor performance if used with large datasets.
    • Files: Using files to store binary files, or custom serialization types

The above mentioned application data including settings and files

And the application data is divided into three categories according to the nature of storage:

    • Local data
    • Roaming data: Users can easily keep app data synchronized across multiple devices
    • Temporary data: Temporary app data store is similar to caching

So the corresponding local settings and local files, roaming settings and roaming files, temporary settings and temporary files

The APIs for different types of settings and files are as follows:

    • Local Settings: ApplicationData.Current.LocalSettings
    • Local file: ApplicationData.Current.LocalFolder
    • Roaming settings: ApplicationData.Current.RoamingSettings
    • Roaming files: ApplicationData.Current.RoamingFolder
    • Temporary settings: ApplicationData.Current.TemporarySettings
    • Temp file: ApplicationData.Current.TemporaryFolder

Basic actions for setting up

setting is an object of type Applicationdatacontainer, refer to the official documentation for the Applicationdatacontainer class, here are just a few simple things to do.

Simple Setup

Applicationdatacontainer localsettings = applicationdata.current.localsettings;//Get local settings, you can also get roaming settings and temporary settings, the following actions are the same            localsettings.values["theme"] = "light";//Add a setting in the local settings, like a dictionary assignment, theme is the key inside the localsettings, and "light" is the value, The types that can be set are listed above            localSettings.Values.Remove ("theme");//Delete setting entry            string theme = localsettings.values["Theme"] As string;//read Setup entry      applicationdatacompositevalue simplesettings = new Applicationdatacompositevalue ();// Create a container for simple settings            simplesettings["theme"] = "light";      simplesettings["FontFamily"] = "Microsoft Jas Black";      localsettings.values["simplesettings"] = simplesettings;//adds a composite setting item to the local settings obtained above      Applicationdatacompositevalue Advancesettings = new Applicationdatacompositevalue ();//Create simple set container            advancesettings["Issync"] = false;      localsettings.values["advancesettings"] = advancesettings;

In this way, the compound operation of the set item can be implemented, the specific operation reference: https://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/ Windows.storage.applicationdatacontainer.aspx

Basic operation of the file

The two basic classes related to file operations are Storagefile and Storagefolder

            Storagefolder folder = applicationdata.current.localfolder;//Get local folders            StorageFile file = await folder. Createfileasync ("First.txt", creationcollisionoption.openifexists);//Create File            await Fileio.writetextasync (file, " The contents of the text ");//use FileIO to write a string to the file      StorageFile fileOpen = folder. Getfileasync ("First.txt");      String content = Await Fileio.readtextasync (fileOpen);//Read text    

The above operation can be applied to roaming data and temporary data, and the data synchronization between multiple devices can be realized by roaming data, but the data synchronization has certain conditions. Temporary data is similar to caching, which can be used to save some cached data, such as a picture cache in a microblog, which is automatically deleted when the system is maintained, or can be deleted manually at any time.

In addition to manipulating data, you can also version data: Using the Application.Version property and Applicationdata.setversionasync

"Reprint" UWP app settings and file settings: Science

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.