ApplicationDataContainer.CreateContainer | createContainer method

Applies to Windows and Windows Phone

Creates or opens the specified settings container in the current settings container.

Syntax


Public Function CreateContainer(
  name As String,  
  disposition As ApplicationDataCreateDisposition 
) As ApplicationDataContainer

Parameters

name

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

The name of the container.

disposition

Type: ApplicationDataCreateDisposition

One of the enumeration values.

Return value

Type: ApplicationDataContainer

The settings container.

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.


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")

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

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

Metadata

Windows.winmd

DLL

Windows.Storage.ApplicationData.dll

See also

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++)
Concepts
Application data overview
Reference
ApplicationDataContainer

 

 

Show:
© 2014 Microsoft