ApplicationData ApplicationData ApplicationData ApplicationData Class

Provides access to the application data store. Application data consists of files and settings that are either local, roaming, or temporary.

Syntax

Declaration

public sealed class ApplicationDatapublic sealed class ApplicationDataPublic NotInheritable Class ApplicationDatapublic sealed class ApplicationData

Remarks

Types of application data

ApplicationData provides local, roaming, and temporary storage for app data on a per-user basis. Use this class to preserve app-specific data between sessions, users, and across multiple devices.

ApplicationData does not provide access to files in an app package. To do this, use InstalledLocation.

Current gives you the app's ApplicationData instance. Use this instance to get app folders or settings.

Folders are used to store app data as files on the file system. App settings are stored in key/value pairs that can be organized in to nested sets. Settings data is saved in the Windows registry.

These are the main types of app data:

  • Local: stored on the device, backed up in the cloud, and persists across updates
  • LocalCache: persistent data that exists on the current device, not backed up, and persists across updates
  • SharedLocal: persistent across all app users
  • Roaming: exists on all devices where the user has installed the app
  • Temporary: can be deleted by the system at any time

Using application folders

LocalFolder persists across updates and gets backed up to the cloud as part of the device backup. Typically, this folder should be used for user data that would be lost if it were not backed up. Some examples of data stored in LocalFolder are:

  • a user drawing for an art app
  • daily exercise history for a fitness app
  • a shopping list for a todo app By storing information in the LocalFolder, the user will not lose data after resetting the device or switching to a new device. For other types of local data that are easy to recreate and not necessary for backup and restore, use the LocalCacheFolder or TemporaryFolder.

LocalCacheFolder and TemporaryFolder are both stored locally and are not backed up to the cloud. LocalCacheFolder is under control of that app and is persistent across app sessions. LocalCacheFolder should be used for generated content needed across app sessions, such as cached files, logs, or authentication tokens. TemporaryFolder is not guaranteed to be persistent across sessions and can be deleted by the system at any time.

RoamingFolder is typically used for user preferences and customizations, links, and small data files. The contents of RoamingFolder roam across the user's devices and app instances. RoamingFolder should not be used for large amounts of data, data specific to a device, or data that relies on instant syncing.

Another folder, SharedLocalFolder, is persistent across app user accounts and should be used for large files accessed by multiple users. There is some extra set up required to access SharedLocalFolder. For more information on accessing and using this folder, see SharedLocalFolder.

You can store your app data in app-specific, versioned formats. For more info, see Version and SetVersionAsync(UInt32, ApplicationDataSetVersionHandler).

For more details on using these APIs, see Store and retrieve settings and other app data.

Examples

The following code example demonstrates how to read or write to an ApplicationData folder of your choice. This example uses the LocalFolder, but the code can be slightly modified to access the LocalCacheFolder, RoamingFolder, SharedLocalFolder, or TemporaryFolder based on how your data should be stored. SharedLocalFolder has some restrictions and needs special permissions to access, for more information, see SharedLocalFolder.


// This example code can be used to read or write to an ApplicationData folder of your choice.

var applicationData = Windows.Storage.ApplicationData.current;
var localFolder = applicationData.localFolder;  // Change this to var roamingFolder = applicationData.roamingFolder;
                                                // to use the RoamingFolder instead, for example.

// 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
      });
}

// This example code can be used to read or write to an ApplicationData folder of your choice.

// Change this to Windows.Storage.StorageFolder roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder
// to use the RoamingFolder instead, for example.
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

// Write data to a file

async void WriteTimestamp()
{
   Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatter = 
       new Windows.Globalization.DatetimeFormatting.DateTimeFormatter("longtime");

   StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt", 
       CreationCollisionOption.ReplaceExisting);
   await FileIO.WriteTextAsync(sampleFile, formatter.Format(DateTime.Now));
}

// Read data from a file

async Task ReadTimestamp()
{
   try
   {
      StorageFile sampleFile = await localFolder.GetFileAsync("dataFile.txt");
      String timestamp = await FileIO.ReadTextAsync(sampleFile);
      // Data is contained in timestamp
   }
   catch (Exception)
   {
      // Timestamp not found
   }
}

' This example code can be used to read or write to an ApplicationData folder of your choice.

' Change this to Dim roamingFolder As Windows.Storage.StorageFolder = Windows.Storage.ApplicationData.Current.RoamingFolder
' to use the RoamingFolder instead, for example.
Dim localFolder As Windows.Storage.StorageFolder = Windows.Storage.ApplicationData.Current.LocalFolder

' Write data to a file

Private Async Sub WriteTimestamp()
   Dim formatter As DateTimeFormatter = New DateTimeFormatter("longtime")

   Dim sampleFile As StorageFile = Await localFolder.CreateFileAsync("dataFile.txt", 
       CreationCollisionOption.ReplaceExisting)
   Await FileIO.WriteTextAsync(sampleFile, formatter.Format(DateTime.Now));
End Sub

' Read data from a file

Private Async Function ReadTimestamp() As Task
   Try
      Dim sampleFile As StorageFile = Await localFolder.GetFileAsync("dataFile.txt")
      Dim timestamp As string = Await FileIO.ReadTextAsync(sampleFile)
      ' Data is contained in timestamp
   Catch e1 As Exception
      ' Timestamp not found
   End Try
End Function

// This example code can be used to read or write to an ApplicationData folder of your choice.

// Change this to StorageFolder^ roamingFolder = ApplicationData::Current->RoamingFolder; to 
// use the RoamingFolder instead, for example.
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;

// Write data to a file

void MainPage::WriteTimestamp()
{
   concurrency::task<StorageFile^> fileOperation = 
       localFolder->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(localFolder->GetFileAsync("dataFile.txt"));
   getFileOperation.then([this](StorageFile^ file)
   {
      return FileIO::ReadTextAsync(file);
   }).then([this](concurrency::task<String^> previousOperation) {
      String^ timestamp;

      try {
         // Data is contained in timestamp
         timestamp = previousOperation.get();
      } catch (...) {
         // Timestamp not found
      }
   });
}

Properties summary

Provides access to the app data store associated with the app's app package.

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

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

Gets the application settings container in the local app data store.

Gets the root folder in the roaming app data store.

Gets the application settings container in the roaming app data store.

Gets the maximum size of the data that can be synchronized to the cloud from the roaming app data store.

Gets the root folder in the shared app data store.

Gets the root folder in the temporary app data store.

Gets the version number of the application data in the app data store.

Methods summary

Removes all application data from the local, roaming, and temporary app data stores.

Note

ClearAsync() method encounters an error if there are any open file handles. You should take care to close all open files prior to calling ClearAsync.

Removes all application data from the specified app data store.

Note

ClearAsync(ApplicationDataLocality) method encounters an error if there are any open file handles. You should take care to close all open files prior to calling ClearAsync.

Clears the files and subfolders from the specified subfolder of the shared storage folder for the publisher of the current app.

Static method that returns the ApplicationData for a User.

Gets the specified subfolder of the shared storage folder for the publisher of the current app.

Sets the version number of the application data in the app data store.

Sends a DataChanged event to all registered event handlers.

Events summary

Occurs when roaming application data is synchronized.

Properties

  • Current
    Current
    Current
    Current

    Provides access to the app data store associated with the app's app package.

    public static ApplicationData Current { get; }public static ApplicationData Current { get; }Public Static ReadOnly Property Current As ApplicationDatapublic static ApplicationData Current { get; }

    Property Value

    Remarks

    Application folders and settings can be accessed through the Windows.Storage.ApplicationData.current property.

  • LocalCacheFolder
    LocalCacheFolder
    LocalCacheFolder
    LocalCacheFolder

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

    public StorageFolder LocalCacheFolder { get; }public StorageFolder LocalCacheFolder { get; }Public ReadOnly Property LocalCacheFolder As StorageFolderpublic StorageFolder LocalCacheFolder { get; }

    Property Value

  • LocalFolder
    LocalFolder
    LocalFolder
    LocalFolder

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

    public StorageFolder LocalFolder { get; }public StorageFolder LocalFolder { get; }Public ReadOnly Property LocalFolder As StorageFolderpublic StorageFolder LocalFolder { get; }

    Property Value

    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 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.

  • LocalSettings
    LocalSettings
    LocalSettings
    LocalSettings

    Gets the application settings container in the local app data store.

    public ApplicationDataContainer LocalSettings { get; }public ApplicationDataContainer LocalSettings { get; }Public ReadOnly Property LocalSettings As ApplicationDataContainerpublic ApplicationDataContainer LocalSettings { get; }

    Property Value

    Remarks

    For both LocalSettings and RoamingSettings, the name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size.

    The Windows Runtime data types are supported for app settings.

    Examples

    Use the LocalSettings property to get the settings in an ApplicationDataContainer object. Use the Values property to access the settings in the localSettings container. This example creates and reads a setting named exampleSetting.

    Call the Remove(String) method to delete the exampleSetting setting when you have finished with it.

    Note that to access the RoamingSettings, use the same process outlined in the example, except change the occurrences of localSettings to roamingSettings

    var applicationData = Windows.Storage.ApplicationData.current;
    
    var localSettings = applicationData.localSettings;
    
    // Create a simple setting
    
    localSettings.values["exampleSetting"] = "Hello Windows";
    
    // Read data from a simple setting
    
    var value = localSettings.values["exampleSetting"];
    
    if (!value)
    {
        // No data
    }
    else
    {
        // Access data in value
    }
    
    // Delete a simple setting
    
    localSettings.values.remove("exampleSetting");
    
    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    
    // Create a simple setting
    
    localSettings.Values["exampleSetting"] = "Hello Windows";
    
    // Read data from a simple setting
    
    Object value = localSettings.Values["exampleSetting"];
    
    if (value == null)
    {
        // No data
    }
    else
    {
        // Access data in value
    }
    
    // Delete a simple setting
    
    localSettings.Values.Remove("exampleSetting");
    
    Dim localSettings As Windows.Storage.ApplicationDataContainer = Windows.Storage.ApplicationData.Current.LocalSettings
    
    ' Create a simple setting
    
    localSettings.Values("exampleSetting") = "Hello Windows";
    
    ' Read data from a simple setting
    
    Dim value As Object = localSettings.Values("exampleSetting")
    
    If value Is Nothing Then
       ' No data
    Else
       ' Access data in value
    End If
    
    ' Delete a simple setting
    
    localSettings.Values.Remove("exampleSetting")
    
    ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
    
    // Create a simple setting
    
    auto values = localSettings->Values;
    values->Insert("exampleSetting", dynamic_cast<PropertyValue^>(PropertyValue::CreateString("Hello Windows")));
    
    // Read data from a simple setting
    
    auto values = localSettings->Values;
    String^ value = safe_cast<String^>(localSettings->Values->Lookup("exampleSetting"));
    
    if (!value)
    {
        // No data
    }
    else
    {
        // Access data in value
    }
    
    // Delete a simple setting
    
    values->Remove("exampleSetting");
    
  • RoamingFolder
    RoamingFolder
    RoamingFolder
    RoamingFolder

    Gets the root folder in the roaming app data store.

    public StorageFolder RoamingFolder { get; }public StorageFolder RoamingFolder { get; }Public ReadOnly Property RoamingFolder As StorageFolderpublic StorageFolder RoamingFolder { get; }

    Property Value

    Remarks

    The sync engine has restrictions on the file name conventions that you must follow to ensure the items in the roaming folder can roam. Be sure that your file and folder names do not contain leading whitespace. The sync engine may limit the total size of settings and files that can roam.

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

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

  • RoamingSettings
    RoamingSettings
    RoamingSettings
    RoamingSettings

    Gets the application settings container in the roaming app data store.

    public ApplicationDataContainer RoamingSettings { get; }public ApplicationDataContainer RoamingSettings { get; }Public ReadOnly Property RoamingSettings As ApplicationDataContainerpublic ApplicationDataContainer RoamingSettings { get; }

    Property Value

    Remarks

    See LocalSettings for remarks and examples on accessing RoamingSettings.

  • RoamingStorageQuota
    RoamingStorageQuota
    RoamingStorageQuota
    RoamingStorageQuota

    Gets the maximum size of the data that can be synchronized to the cloud from the roaming app data store.

    public ulong RoamingStorageQuota { get; }public ulong RoamingStorageQuota { get; }Public ReadOnly Property RoamingStorageQuota As ulongpublic ulong RoamingStorageQuota { get; }

    Property Value

    • ulong
      ulong
      ulong
      ulong

      The maximum size of the data, in KB.

    Remarks

    If the current size of the roaming data in the roaming app data store exceeds the maximum size specified by RoamingStorageQuota, the system suspends data replication for all apps in the package to the cloud until the current size no longer exceeds the maximum size.

  • SharedLocalFolder
    SharedLocalFolder
    SharedLocalFolder
    SharedLocalFolder

    Gets the root folder in the shared app data store.

    public StorageFolder SharedLocalFolder { get; }public StorageFolder SharedLocalFolder { get; }Public ReadOnly Property SharedLocalFolder As StorageFolderpublic StorageFolder SharedLocalFolder { get; }

    Property Value

    Remarks

    Accessing SharedLocalFolder

    SharedLocalFolder is only available if the device has the appropriate group policy. If the group policy is not enabled, the device administrator must enable it. From Local Group Policy Editor, navigate to Computer Configuration\Administrative Templates\Windows Components\App Package Deployment, then change the setting "Allow a Windows app to share application data between users" to "Enabled."

    After the group policy is enabled, SharedLocalFolder can be accessed.

  • TemporaryFolder
    TemporaryFolder
    TemporaryFolder
    TemporaryFolder

    Gets the root folder in the temporary app data store.

    public StorageFolder TemporaryFolder { get; }public StorageFolder TemporaryFolder { get; }Public ReadOnly Property TemporaryFolder As StorageFolderpublic StorageFolder TemporaryFolder { get; }

    Property Value

    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="" />

  • Version
    Version
    Version
    Version

    Gets the version number of the application data in the app data store.

    public uint Version { get; }public uint Version { get; }Public ReadOnly Property Version As uintpublic uint Version { get; }

    Property Value

    • uint
      uint
      uint
      uint

      The version number of the application data.

Methods

  • ClearAsync()
    ClearAsync()
    ClearAsync()
    ClearAsync()

    Removes all application data from the local, roaming, and temporary app data stores.

    Note

    ClearAsync() method encounters an error if there are any open file handles. You should take care to close all open files prior to calling ClearAsync.

    public IAsyncAction ClearAsync()public IAsyncAction ClearAsync()Public Function ClearAsync() As IAsyncActionpublic IAsyncAction ClearAsync()

    Returns

  • ClearAsync(ApplicationDataLocality)
    ClearAsync(ApplicationDataLocality)
    ClearAsync(ApplicationDataLocality)
    ClearAsync(ApplicationDataLocality)

    Removes all application data from the specified app data store.

    Note

    ClearAsync(ApplicationDataLocality) method encounters an error if there are any open file handles. You should take care to close all open files prior to calling ClearAsync.

    public IAsyncAction ClearAsync(ApplicationDataLocality locality)public IAsyncAction ClearAsync(ApplicationDataLocality locality)Public Function ClearAsync(locality As ApplicationDataLocality) As IAsyncActionpublic IAsyncAction ClearAsync(ApplicationDataLocality locality)

    Parameters

    Returns

  • ClearPublisherCacheFolderAsync(String)
    ClearPublisherCacheFolderAsync(String)
    ClearPublisherCacheFolderAsync(String)
    ClearPublisherCacheFolderAsync(String)

    Clears the files and subfolders from the specified subfolder of the shared storage folder for the publisher of the current app.

    public IAsyncAction ClearPublisherCacheFolderAsync(String folderName)public IAsyncAction ClearPublisherCacheFolderAsync(String folderName)Public Function ClearPublisherCacheFolderAsync(folderName As String) As IAsyncActionpublic IAsyncAction ClearPublisherCacheFolderAsync(String folderName)

    Parameters

    • folderName
      System.String
      System.String
      System.String
      System.String

      The subfolder of the shared storage folder for the publisher of the current app from which to clear the files and subfolders.

    Returns

    • Represents an asynchronous action that does not return a result and does not have progress notifications. You can use this value to get the results of the operation, or to specify a method to run when the operation completes - for example, to repopulate the shared storage folder with new data.

    Remarks

    For more info about how to share files and folders among apps from the same publisher, see GetPublisherCacheFolder(String).

  • GetForUserAsync(User)
    GetForUserAsync(User)
    GetForUserAsync(User)
    GetForUserAsync(User)

    Static method that returns the ApplicationData for a User.

    public static IAsyncOperation<ApplicationData> GetForUserAsync(User user)public static IAsyncOperation<ApplicationData> GetForUserAsync(User user)Public Static Function GetForUserAsync(user As User) As IAsyncOperation( Of ApplicationData )public static IAsyncOperation<ApplicationData> GetForUserAsync(User user)

    Parameters

    Returns

    • When this method completes, it returns the requested ApplicationData object.

  • GetPublisherCacheFolder(String)
    GetPublisherCacheFolder(String)
    GetPublisherCacheFolder(String)
    GetPublisherCacheFolder(String)

    Gets the specified subfolder of the shared storage folder for the publisher of the current app.

    public StorageFolder GetPublisherCacheFolder(String folderName)public StorageFolder GetPublisherCacheFolder(String folderName)Public Function GetPublisherCacheFolder(folderName As String) As StorageFolderpublic StorageFolder GetPublisherCacheFolder(String folderName)

    Parameters

    • folderName
      System.String
      System.String
      System.String
      System.String

      The subfolder to get from the shared storage folder for the publisher of the current app.

    Returns

    Remarks

    The strong security model of Windows Runtime app typically prevents apps from sharing data among themselves. It can be useful, however, for apps from the same publisher to share files and settings on a per-user basis. As an app publisher, you can register your app to share a storage folder with other apps that you publish by adding extensions to the app manifest.

    Here are some examples of how you can use this shared storage folder if you publish multiple apps.

    • Share files. For example, if multiple apps use the same images or the same custom fonts, you can save these files in the shared storage folder.
    • Share the user's settings in a custom settings file. For example, if multiple apps use temperatures, you can save a copy of the user's preference for Celsius or Fahrenheit in a custom settings file in the shared storage folder. We recommend that you also store the user's settings with each app or in another master location, however, since the user can clear the contents of the shared storage folder. The shared storage folder for the app publisher is automatically provisioned when the user installs the first app from the publisher.

    The shared storage folder has the following requirements and restrictions.

    • Data in the shared storage folder is not backed up or roamed. Also, the user can clear the contents of the shared storage folder.
    • You cannot use this feature to share data among apps from different publishers.
    • You cannot use this feature to share data among different users.
    • The shared storage folder does not have version management. To register an app to use the publisher's shared storage folder

    Manually enter XML similar to the following example in the app manifest to register subfolders. You don't have to create these subfolders. They are automatically provisioned for you.

    <Package>
        …
        <Extensions>
            …
            <Extension Category=”windows.publisherCacheFolders”>
                <PublisherCacheFolder>
                    <Folder Name="Folder1">
                    <Folder Name="Folder2">
                </PublisherCacheFolder>
            </Extension>
            …
        </Extensions>
        …
    </Package>
    

    To access data in the publisher's shared storage folder

    Call the GetPublisherCacheFolder(String) method to get one of the registered subfolders from the shared storage folder.

    Then use the properties and methods of the StorageFolder class to read and write files and subfolders in the shared folder.

    Access to the shared storage folder has the following requirements and restrictions.

    • There is no default subfolder. You have to specify a subfolder when you call the GetPublisherCacheFolder(String) method.
    • You can only access subfolders registered in the app manifest.
    • You can't access the root of the shared storage folder. To clean up the data in the publisher's shared storage folder

    Call the ClearPublisherCacheFolderAsync(String) method to clear the files and subfolders from the specified subfolder of the shared storage folder for the publisher of the current app.

    The shared storage folder is automatically cleaned up when the last app from the publisher is uninstalled.

    Data saved in the shared storage folder is not linked to the app that saved it. When you uninstall the app that saved the data, the data remains in the shared storage folder until the last app from the same publisher is uninstalled.

  • SetVersionAsync(UInt32, ApplicationDataSetVersionHandler)
    SetVersionAsync(UInt32, ApplicationDataSetVersionHandler)
    SetVersionAsync(UInt32, ApplicationDataSetVersionHandler)
    SetVersionAsync(UInt32, ApplicationDataSetVersionHandler)

    Sets the version number of the application data in the app data store.

    public IAsyncAction SetVersionAsync(UInt32 desiredVersion, ApplicationDataSetVersionHandler handler)public IAsyncAction SetVersionAsync(UInt32 desiredVersion, ApplicationDataSetVersionHandler handler)Public Function SetVersionAsync(desiredVersion As UInt32, handler As ApplicationDataSetVersionHandler) As IAsyncActionpublic IAsyncAction SetVersionAsync(UInt32 desiredVersion, ApplicationDataSetVersionHandler handler)

    Parameters

    Returns

    Remarks

    Versioning enables you to change the application data format used in a future release of your app without causing compatibility problems with previous releases of your app. The app checks the version of the data in the data store, and if it is less than the version the app expects, the app should update the application data to the new format and update the version.

    It is strongly recommended that you use sequential and incrementing version numbers, starting at 1.

  • SignalDataChanged()
    SignalDataChanged()
    SignalDataChanged()
    SignalDataChanged()

    Sends a DataChanged event to all registered event handlers.

    public void SignalDataChanged()public void SignalDataChanged()Public Function SignalDataChanged() As voidpublic void SignalDataChanged()

    Remarks

    You can use the SignalDataChanged() method to fire a DataChanged event that you can use to signal other code in your app to reload the local state.

    The system automatically fires the DataChanged event when the roaming state changes. After those changes are roamed to other devices, any instance of your app that is running on those devices will also be able to respond to the DataChanged event by refreshing their roaming state.

Events

  • DataChanged
    DataChanged
    DataChanged
    DataChanged

    Occurs when roaming application data is synchronized.

    public event TypedEventHandler DataChangedpublic event TypedEventHandler DataChangedPublic Event DataChangedpublic event TypedEventHandler DataChanged

    Remarks

    Examples

    This example registers for the DataChanged event.

    
    var applicationData = Windows.Storage.ApplicationData.current;
    
    function initialize() 
    {
        applicationData.addEventListener("datachanged", datachangeHandler);
    }
    
    function dataChangeHandler(eventArgs)
    {
        // TODO: Refresh your data
    }
    
    void InitHandlers()
    {
       Windows.Storage.ApplicationData.Current.DataChanged += 
          new TypedEventHandler<ApplicationData, object>(DataChangeHandler);
    }
    
    void DataChangeHandler(Windows.Storage.ApplicationData appData, object o)
    {
       // TODO: Refresh your data
    }
    
    Private Sub InitHandlers()
        AddHandler Windows.Storage.ApplicationData.Current.DataChanged, AddressOf DataChangeHandler
    End Sub
    
    Private Sub DataChangeHandler(ByVal appData As Windows.Storage.ApplicationData, ByVal o As Object)
        ' TODO: Refresh your data
    End Sub
    
    void MainPage::InitHandlers()
    {
       Windows::Storage::ApplicationData::Current->DataChanged += 
          ref new TypedEventHandler<Windows::Storage::ApplicationData^, Object^>
          (this, &MainPage::DataChangeHandler);
    }
    
    void MainPage::DataChangeHandler(Windows::Storage::ApplicationData^ appData, Object^)
    {
       // TODO: Refresh your data
    }
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Storage.dll