I. Overview of temporary Application data
Temporary application data is equivalent to caching in Web pages, which are not capable of roaming and can be deleted at any time.
It is common for the system to remove these temporary application data at any time in order to maintain the task, and we can also delete the data by "Disk Cleanup".
In general, we store the temporary information during the session in the application, such as QQ chat record and so on.
Second, how to build temporary application data
1. 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
Create and update files in the temporary application data store using Windows.Storage.StorageFolder.CreateFileAsync and Windows.Storage.FileIO.WriteTextAsync.
Async
void Writetimestamp ()
{
Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatter =
New Windows.Globalization.DatetimeFormatting.DateTimeFormatter ("longtime");
Storagefile Samplefile = await Temporaryfolder.createfileasync ("DataFile.txt",
createcollisionoption.replaceexisting);
Await Fileio.writetextasync (Samplefile, formatter. Format (DateTime.Now);
}
3, from the file to obtain temporary data
Use Windows.Storage.StorageFolder.GetFileAsync, Windows.Storage.StorageFile.GetFileFromApplicationUriAsync and Windows.Storage.FileIO.ReadTextAsync opens and reads files in the temporary application data store.
Async
void Readtimestamp ()
{
try
{
Storagefile samplefile = await Temporaryfolder.getfileasync ("DataFile.txt");
String timestamp = await fileio.readtextasync (samplefile);
}
catch (Exception)
{
}
}