ApplicationData.TemporaryFolder | temporaryFolder property

Applies to Windows and Windows Phone

Gets the root folder in the temporary app data store.

Syntax


public:
property StorageFolder^ TemporaryFolder { 
   StorageFolder^ get();
}

Property value

Type: StorageFolder

The file system folder that contains the files.

Remarks

You can access files in the temporary app data store using the "ms-appdata:///temp/" protocol. For example:

<img src="ms-appdata:///temp/myFile.png" alt="" />

Examples

Use the file APIs, such as Windows.Storage.StorageFolder.CreateFileAsync | createFileAsync and Windows.Storage.FileIO.WriteTextAsync | writeTextAsync, to create and update a file in the temporary app data store. This example creates a file named dataFile.txt in the temporaryFolder container and writes the current date and time to the file. The ReplaceExisting | replaceExisting value from the CreationCollisionOption enumeration indicates that the file should be replaced if it already exists.

Next, this example opens the dataFile.txt file created and reads the date from the file using Windows.Storage.FileIO.ReadTextAsync | readTextAsync.


StorageFolder^ temporaryFolder = ApplicationData::Current->TemporaryFolder;

// Write data to a file

void MainPage::WriteTimestamp()
{
   concurrency::task<StorageFile^> fileOperation = 
       temporaryFolder->CreateFileAsync("dataFile.txt", CreationCollisionOption::ReplaceExisting);
   fileOperation.then([this](StorageFile^ sampleFile)
   {
      auto calendar = ref new Calendar;
      auto now = calendar->ToDateTime();
      auto formatter = ref new Windows::Globalization::DateTimeFormatting::DateTimeFormatter("longtime");

      return FileIO::WriteTextAsync(sampleFile, formatter->Format(now));
   }).then([this](task<void> previousOperation) {
      try {
         previousOperation.get();
      } catch (Platform::Exception^) {
         // Timestamp not written
      }
   });
}

// Read data from a file

void MainPage::ReadTimestamp()
{
   concurrency::task<StorageFile^> getFileOperation(temporaryFolder->GetFileAsync("dataFile.txt"));
   getFileOperation.then([this](StorageFile^ file)
   {
      return FileIO::ReadTextAsync(file);
   }).then([this](concurrency::task<String^> previousOperation) {
      String^ timestamp;
 
      try {
         timestamp = previousOperation.get();
         // Data is contained in timestamp
      } catch (...) {
         // Timestamp not found
      }
   });
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

DLL

Windows.Storage.ApplicationData.dll

See also

Tasks
Quickstart: Temporary application data (JavaScript)
Quickstart: Temporary application data (C#/VB/C++)
Concepts
Application data overview
Reference
ApplicationData

 

 

Show:
© 2014 Microsoft