LocalCacheFolder property

ApplicationData.LocalCacheFolder | localCacheFolder property

Gets the folder in the local app data store where you can save files that are not included in backup and restore.

Syntax


var localCacheFolder = applicationData.localCacheFolder;

Property value

Type: StorageFolder

The folder in the local app data store where you can save files that are not included in backup and restore.

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 local cache app data store. This example creates a file named dataFile.txt in the localCacheFolder 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.


var applicationData = Windows.Storage.ApplicationData.current;
var localCacheFolder = applicationData.localCacheFolder;

// Write data to a file

function writeTimestamp() {
   localCacheFolder.createFileAsync("dataFile.txt", Windows.Storage.CreationCollisionOption.replaceExisting)
      .then(function (sampleFile) {
         var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime");
         var timestamp = formatter.format(new Date());

         return Windows.Storage.FileIO.writeTextAsync(sampleFile, timestamp);
      }).done(function () {      
      });
}

// Read data from a file

function readTimestamp() {
   localCacheFolder.getFileAsync("dataFile.txt")
      .then(function (sampleFile) {
         return Windows.Storage.FileIO.readTextAsync(sampleFile);
      }).done(function (timestamp) {
         // Data is contained in timestamp
      }, function () {
         // Timestamp not found
      });
}

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

None supported

Minimum supported server

None supported

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

See also

ApplicationData

 

 

Show:
© 2017 Microsoft