Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ApplicationData.LocalFolder | localFolder property

Gets the root folder in the local app data store. This folder is backed up to the cloud.

Syntax


var localFolder = applicationData.localFolder;

Property value

Type: StorageFolder

The file system folder that contains the files.

Remarks

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

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

To access files in the app package, use Windows.ApplicationModel.Package.Current.InstalledLocation.

To request that Windows index your app data for search, create a folder named "Indexed" under this folder and store the files that you want indexed there. Windows indexes the file content and metadata (properties) in this "Indexed" folder and all its subfolders.

If the device that runs this app supports app data backup, any content placed on LocalFolder will be eligible to be backed up to the cloud. Therefore if you want to persist data and keep it local to the device you should consider using LocalCacheFolder.

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


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

// Write data to a file

function writeTimestamp() {
   localFolder.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() {
   localFolder.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

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

See also

Tasks
Quickstart: Local application data (JavaScript)
Store and retrieve settings and other app data
Concepts
Store and retrieve settings and other app data
Reference
ApplicationData

 

 

Show: