First, the theory
1. Where are the various data of the app in WP?
This is a good introduction to the problem. There are Installtionfolder, Knownfolder, SD Card ...
2. An app 's data storage Overview
Two major parts, InstallationFolder and app Data Folder
3, Windows.Storage.ApplicationData and windows.security. Credentials Brief introduction
With the use of Windows.Storage.ApplicationData, we can get 3 different WP folders and 2 settings to save the dictionary, C # operation as follows
Windows.Storage.StorageFolder roam == = = = Windows.Storage.ApplicationData.Current.RoamingSettings;
Second, local Folder and local Setting
1, localsetting use, C # code as follows:
//Create a simple settinglocalsettings.values["examplesetting"] ="Hello Windows";//Read data from a simple settingObject value = localsettings.values["examplesetting"];if(Value = =NULL){ //No Data}Else{ //Access data in value}//Delete a simple settingLocalSettings.Values.Remove ("examplesetting");
2, Localfolder use, C # code as follows:
Private Async voidWritetexttolocalstoragefile (stringFileNamestringtext) { varfold = Windows.Storage.ApplicationData.Current.LocalFolder;//Open FolderStorageFile file =awaitFold. Createfileasync (filename, creationcollisionoption.replaceexisting);//Create a file awaitFileio.writetextasync (file, text);//write content in a file } Private Asynctask<string> Readtextfromlocalstorage (stringfilename) { varfold = Windows.Storage.ApplicationData.Current.LocalFolder;//Open FolderStorageFile file =awaitFold. Getfileasync (filename);//Open the corresponding file stringresult =awaitFileio.readtextasync (file);//read the contents of the file returnresult; }
Note: Here the operation of the file is very simple, the steps are in the computer to manage the file steps are similar.
Iii. Roaming Setting and Roaming Folder
If a user installs your program on multiple devices, it's a good experience if all the devices can share the same settings information. And roaming data provides an application that can synchronize the methods and settings on multiple different physical devices. It is automatically stored in the user's OneDrive format as a folder and as a dictionary of settings. The size of Roaming data is limited to Applicationdata.roamingstoragequota (typically around 100k, but it does not occupy the space of your OneDrive). The synchronization process diagram is as follows:
The Roaming Setting and Roaming Folder operate in the same way as the local folder and local Setting, which are not described here. However, roaming data change events need to be monitored in different devices. The C # code is as follows:
Windows.Storage.ApplicationData.Current.DataChanged + = current_datachanged, ... . void Object args) { // Refresh your settings...}
Synchronization of data occurs in the background.
Iv. ways to obtain files in several different ways
wp8.1 Study10:app Data storage