Introduction to Windows 8 style application Development 28 temporary application data

Source: Internet
Author: User

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)   

   {

   }

}

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.