ApplicationDataContainer
ApplicationDataContainer
ApplicationDataContainer
ApplicationDataContainer
Class
Definition
Represents a container for app settings. The methods and properties of this class support creating, deleting, enumerating, and traversing the container hierarchy.
public : sealed class ApplicationDataContainer : IApplicationDataContainerpublic sealed class ApplicationDataContainer : IApplicationDataContainerPublic NotInheritable Class ApplicationDataContainer Implements IApplicationDataContainer// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Examples
Call the ApplicationDataContainer.CreateContainer | createContainer method to create a settings container. This example creates a settings container named exampleContainer and adds a setting named exampleSetting. The Always | always value from the ApplicationDataCreateDisposition enumeration indicates that the container should be created if it does not already exist.
Use the ApplicationDataContainer.Values | values property to access the exampleSetting setting in the exampleContainer container.
Call the ApplicationDataContainer.DeleteContainer | deleteContainer method to delete the exampleContainer settings container when you have finished with it.
var applicationData = Windows.Storage.ApplicationData.current;
var localSettings = applicationData.localSettings;
// Create a setting in a container
var container = localSettings.createContainer("exampleContainer",
Windows.Storage.ApplicationDataCreateDisposition.Always);
if (localSettings.containers.hasKey("exampleContainer"))
{
localSettings.containers.lookup("exampleContainer").values["exampleSetting"] = "Hello Windows";
}
// Read data from a setting in a container
var hasContainer = localSettings.containers.hasKey("exampleContainer");
if (hasContainer)
{
// Access data in:
// localSettings.containers.lookup("exampleContainer").values.hasKey("exampleSetting");
}
// Delete a container
localSettings.deleteContainer("exampleContainer");
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a setting in a container
Windows.Storage.ApplicationDataContainer container =
localSettings.CreateContainer("exampleContainer", Windows.Storage.ApplicationDataCreateDisposition.Always);
if (localSettings.Containers.ContainsKey("exampleContainer"))
{
localSettings.Containers["exampleContainer"].Values["exampleSetting"] = "Hello Windows";
}
// Read data from a setting in a container
bool hasContainer = localSettings.Containers.ContainsKey("exampleContainer");
bool hasSetting = false;
if (hasContainer)
{
hasSetting = localSettings.Containers["exampleContainer"].Values.ContainsKey("exampleSetting");
}
// Delete a container
localSettings.DeleteContainer("exampleContainer");
Dim localSettings As Windows.Storage.ApplicationDataContainer = Windows.Storage.ApplicationData.Current.LocalSettings
' Create a setting in a container
Dim container As Windows.Storage.ApplicationDataContainer =
localSettings.CreateContainer("exampleContainer", Windows.Storage.ApplicationDataCreateDisposition.Always)
If localSettings.Containers.ContainsKey("exampleContainer") Then
localSettings.Containers("exampleContainer").Values("exampleSetting") = "Hello Windows"
End If
' Read data from a setting in a container
Dim hasContainer As Boolean = localSettings.Containers.ContainsKey("exampleContainer")
Dim hasSetting As Boolean = False
If hasContainer Then
hasSetting = localSettings.Containers("exampleContainer").Values.ContainsKey("exampleSetting")
End If
' Delete a container
localSettings.DeleteContainer("exampleContainer")
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
// Create a setting in a container
ApplicationDataContainer^ container =
localSettings->CreateContainer("exampleContainer", ApplicationDataCreateDisposition::Always);
if (localSettings->Containers->HasKey("exampleContainer"))
{
auto values = localSettings->Containers->Lookup("exampleContainer")->Values;
values->Insert("exampleSetting", "Hello Windows");
}
// Read data from a setting in a container
bool hasContainer = localSettings->Containers->HasKey("exampleContainer");
bool hasSetting = false;
if (hasContainer)
{
auto values = localSettings->Containers->Lookup("exampleContainer")->Values;
hasSetting = values->HasKey("exampleSetting");
}
// Delete a container
localSettings->DeleteContainer("exampleContainer");
Remarks
Note
There is no settings container for the temporary app data store.
The Values property gets an ApplicationDataContainerSettings object that provides access to the settings stored in the container.
Properties
Containers Containers Containers Containers
Gets the child application settings containers of this application settings container.
public : IMapView<string, ApplicationDataContainer> Containers { get; }public IReadOnlyDictionary<string, ApplicationDataContainer> Containers { get; }Public ReadOnly Property Containers As IReadOnlyDictionary<string, ApplicationDataContainer>// You can use this property in JavaScript.
- Value
- IMapView<PlatForm::String, ApplicationDataContainer> IReadOnlyDictionary<string, ApplicationDataContainer> IReadOnlyDictionary<string, ApplicationDataContainer> IReadOnlyDictionary<string, ApplicationDataContainer>
The application settings containers.
- See Also
Locality Locality Locality Locality
Gets the type (local or roaming) of the app data store that is associated with the current settings container.
public : ApplicationDataLocality Locality { get; }public ApplicationDataLocality Locality { get; }Public ReadOnly Property Locality As ApplicationDataLocality// You can use this property in JavaScript.
- Value
- ApplicationDataLocality ApplicationDataLocality ApplicationDataLocality ApplicationDataLocality
One of the enumeration values.
Remarks
There is no temporary settings container, so the ApplicationDataLocality.Temporary value can't be returned by this property.
Name Name Name Name
Gets the name of the current settings container.
public : PlatForm::String Name { get; }public string Name { get; }Public ReadOnly Property Name As string// You can use this property in JavaScript.
- Value
- PlatForm::String string string string
The name of the settings container.
Values Values Values Values
Gets an object that represents the settings in this settings container.
public : IPropertySet Values { get; }public IPropertySet Values { get; }Public ReadOnly Property Values As IPropertySet// You can use this property in JavaScript.
The settings map object.
Remarks
For an example of using an ApplicationData property to get its associated ApplicationDataContainer.Values, see LocalSettings.
- See Also
Methods
CreateContainer(String, ApplicationDataCreateDisposition) CreateContainer(String, ApplicationDataCreateDisposition) CreateContainer(String, ApplicationDataCreateDisposition) CreateContainer(String, ApplicationDataCreateDisposition)
Creates or opens the specified settings container in the current settings container.
public : ApplicationDataContainer CreateContainer(PlatForm::String name, ApplicationDataCreateDisposition disposition)public ApplicationDataContainer CreateContainer(String name, ApplicationDataCreateDisposition disposition)Public Function CreateContainer(name As String, disposition As ApplicationDataCreateDisposition) As ApplicationDataContainer// You can use this method in JavaScript.
- name
- PlatForm::String String String String
The name of the container.
- disposition
- ApplicationDataCreateDisposition ApplicationDataCreateDisposition ApplicationDataCreateDisposition ApplicationDataCreateDisposition
One of the enumeration values.
The settings container.
- See Also
DeleteContainer(String) DeleteContainer(String) DeleteContainer(String) DeleteContainer(String)
Deletes the specified settings container, its subcontainers, and all application settings in the hierarchy.
public : void DeleteContainer(PlatForm::String name)public void DeleteContainer(String name)Public Function DeleteContainer(name As String) As void// You can use this method in JavaScript.
- name
- PlatForm::String String String String
The name of the settings container.
- See Also