Original: Quick build Windows 8 style app 28-temporary app data
This post focuses on temporary app data overview and how to build temporary app data.
I. Overview of temporary application Data
Temporary app data is equivalent to caching in Web pages, which are not capable of roaming and can be deleted at any time.
Usually the system can delete these temporary application data for maintenance tasks at any time, and we can delete the data through Disk Cleanup.
In general, we store temporary information during the session, for example: QQ chat record and so on.
second, how to build temporary application data1. Declaring temporary storage objects
Use the Applicationdata.temporaryfolder property to get the file.
Windows.Storage.StorageFolder temporaryfolder = ApplicationData.Current.TemporaryFolder;
2. Write temporary data to file
Using Windows.Storage.StorageFolder.CreateFileAsync and Windows.Storage.FileIO.WriteTextAsync Create and update files in the temporary app data store.
void Writetimestamp ()
{
New Windows.Globalization.DatetimeFormatting.DateTimeFormatter ("longtime");
StorageFile Samplefile = await Temporaryfolder.createfileasync ("DataFile.txt"
createcollisionoption.replaceexisting);
Await Fileio.writetextasync (Samplefile, formatter. Format (DateTime.Now));
}
3. Get temporary data from the file
Use Windows.Storage.StorageFolder.GetFileAsync, Windows.Storage.StorageFile.GetFileFromApplicationUriAsync and Windows.Storage.FileIO.ReadTextAsync Open and read files in the temporary app data store.
void Readtimestamp ()
{
Try
{
StorageFile Samplefile = await Temporaryfolder.getfileasync ("DataFile.txt");
String timestamp = await fileio.readtextasync (samplefile);
}
Catch (Exception)
{
}
}
The relevant information can be consulted:
1. Application data;
2. Examples of application data;
3.Windows.Storage.ApplicationData;
4.Windows.Storage.ApplicationDataCompositeValue;
5.Windows.Storage.ApplicationDataContainer;
6.Windows.Storage.ApplicationDataContainerSettings;
Quickly build Windows 8 style Apps 28-temporary app data