Aplicativos do Windows
Recolher sumário
Expandir sumário
EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

ApplicationData class

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

Syntax


Public NotInheritable Class ApplicationData

Members

The ApplicationData class has these types of members:

Events

The ApplicationData class has these events.

EventDescription
DataChanged Occurs when roaming application data is synchronized.

 

Methods

The ApplicationData class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
ClearAsync() Removes all application data from the local, roaming, and temporary app data stores.
ClearAsync(ApplicationDataLocality) Removes all application data from the specified app data store.
ClearPublisherCacheFolderAsync Clears the files and subfolders from the specified subfolder of the shared storage folder for the publisher of the current app.
GetForUserAsync Static method that returns the ApplicationData for a User.
GetPublisherCacheFolder Gets the specified subfolder of the shared storage folder for the publisher of the current app.
SetVersionAsync Sets the version number of the application data in the app data store.
SignalDataChanged Sends a DataChanged | datachanged event to all registered event handlers.

 

Properties

The ApplicationData class has these properties.

PropertyAccess typeDescription

Current

Read-only

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

LocalCacheFolder

Read-only

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

LocalFolder

Read-only

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

LocalSettings

Read-only

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

RoamingFolder

Read-only

Gets the root folder in the roaming app data store.

RoamingSettings

Read-only

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

RoamingStorageQuota

Read-only

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

SharedLocalFolder

Read-only

Gets the root folder in the shared app data store.

TemporaryFolder

Read-only

Gets the root folder in the temporary app data store.

Version

Read-only

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

 

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 Windows.ApplicationModel.Package.InstalledLocation.

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

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

Examples

The following code example demonstrates how to get the local settings container for the app.


Dim localSettings As Windows.Storage.ApplicationDataContainer = Windows.Storage.ApplicationData.Current.LocalSettings

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 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(MTA)]
[Version(0x06020000)]

See also

Object
Tasks
Quickstart: Local application data (JavaScript)
Quickstart: Roaming application data (JavaScript)
Quickstart: Temporary application data (JavaScript)
Concepts
Store and retrieve settings and other app data
Guidelines
Guidelines for roaming application data
Guidelines for app settings
Reference
ApplicationDataCompositeValue
ApplicationDataContainer
ApplicationDataContainerSettings
Samples
Application settings sample (Windows 8.1, Windows Phone 8.1)
Application data sample (Windows 8.1, Windows Phone 8.1)
Application data sample (Windows 10)

 

 

Mostrar:
© 2016 Microsoft