This sample shows you how to store and retrieve data that is specific to each user and Windows Runtime app by using the Windows Runtime application data APIs (Windows.Storage.ApplicationData and so on).
Note This sample was created using one of the universal app templates available in Visual Studio. It shows how its solution is structured so it can run on both Windows 8.1 and Windows Phone 8.1. For more info about how to build apps that target Windows and Windows Phone with Visual Studio, see Build apps that target Windows and Windows Phone 8.1 by using Visual Studio.
Application data includes session state, user preferences, and other settings. It is created, read, updated, and deleted when the app is running. The operating system manages these data stores for your app:
- local: Data that exists on the current device and is backed up in the cloud
- roaming: Data that exists on all devices on which the user has installed the app
- temporary: Data that could be removed by the system any time the app isn't running
- localcache: Persistent data that exists only on the current device
If you use roaming data in your app, your users can easily keep your app's application data in sync across multiple devices. The operating system replicates roaming data to the cloud when it is updated, and synchronizes the data to any other devices on which the app is installed, reducing the amount of setup work that the user needs to do to install your app on multiple devices.
If you use local data in your app, your users can back up application data in the cloud. This application data can then be restored back on any other device while setting up the device with the same account.
The sample covers these key tasks:
- Reading and writing settings to an app data store
- Reading and writing files to an app data store
- Responding to roaming events
To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.
To obtain an evaluation copy of Microsoft Visual Studio 2013 Update 2, go to Microsoft Visual Studio 2013.
Related topics
- Windows 8 app samples
- Tasks
- Quickstart: Local application data (JavaScript)
- Quickstart: Local application data (C#/VB/C++)
- Quickstart: Roaming application data (JavaScript)
- Quickstart: Roaming application data (C#/VB/C++)
- Quickstart: Temporary application data (JavaScript)
- Quickstart: Temporary application data (C#/VB/C++)
- Guidelines
- Guidelines for roaming application data
- Concepts
- Application data
- Reference
- Windows.Storage.ApplicationData
- Windows.Storage.ApplicationDataCompositeValue
- Windows.Storage.ApplicationDataContainer
- Windows.Storage.ApplicationDataContainerSettings
- WinJS.Application
Operating system requirements
| Client | |
|---|---|
| Server | |
| Phone |
Build the sample
- Start Visual Studio 2013 Update 2 and select File > Open > Project/Solution.
- Go to the directory to which you unzipped the sample. Then go to the subdirectory named for the sample and double-click the Visual Studio 2013 Update 2 Solution (.sln) file.
- Follow the steps for the version of the sample you want:
-
To build the Windows version of the sample:
- Select ApplicationDataSample.Windows in Solution Explorer.
- Press Ctrl+Shift+B, or use Build > Build Solution, or use Build > Build ApplicationDataSample.Windows.
-
To build the Windows Phone version of the sample:
- Select ApplicationDataSample.WindowsPhone in Solution Explorer.
- Press Ctrl+Shift+B or use Build > Build Solution or use Build > Build ApplicationDataSample.WindowsPhone.
-
Run the sample
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
Deploying the sample
-
To deploy the built Windows version of the sample:
- Select ApplicationDataSample.Windows in Solution Explorer.
- Use Build > Deploy Solution or Build > Deploy ApplicationDataSample.Windows.
-
To deploy the built Windows Phone version of the sample:
- Select ApplicationDataSample.WindowsPhone in Solution Explorer.
- Use Build > Deploy Solution or Build > Deploy ApplicationDataSample.WindowsPhone.
Deploying and running the sample
-
To deploy and run the Windows version of the sample:
- Right-click ApplicationDataSample.Windows in Solution Explorer and select Set as StartUp Project.
- To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
-
To deploy and run the Windows Phone version of the sample:
- Right-click ApplicationDataSample.WindowsPhone in Solution Explorer and select Set as StartUp Project.
- To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.