HTML and CSS Reference
In-Depth Information
with another form of storage that involves a section of the disk that is private to each application and
totally invisible to others.
Storage options in Windows 8
Windows Store applications have three options as far as storage is concerned. In Chapter 9, you
practiced with LocalSettings ; earlier in this chapter you also practiced with files in the local disk. These
are two of the three storage options for a Windows Store application. The third option consists in a
section of the local disk that is reserved to the application. Let's briefly compare the three options to
identify proper use-cases for each.
Saving to the localSettings storage
The localSettings storage is a data container specific to the application that takes the form of a
dictionary. You access it programmatically, as shown below:
var applicationData = Windows.Storage.ApplicationData.current;
var localSettings = applicationData.localSettings;
You read and write data to the container using the classic dictionary approach. Each entry is
uniquely identified by a key and references a value. The key is a string of up to 255 characters in
length; the value can be any valid Windows 8 type (including arrays and collections of custom types)
not larger than 8 KB. You used the localSettings already in Chapter 9 to store the default settings of
the TodoList application. Here's how you write and read an entry to the store:
// Write to the store
localSettings.values["sampleKey"] = "Some data";
// Read from the store
var value = localSettings.values["sampleKey"];
The localSettings dictionary provides a fairly rich programming interface with methods to remove
an item, check for existence, and also some query commands. You can find out more looking at the
MSDN documentation for the ApplicationDataContainerSettings class at the following URL: http://
msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdatacontainersettings.
The localSettings store is not limited to storing only user preferences and also can be used to store
live data of the application. However, the dictionary layout and limitations in the size of individual
entries make it a good choice for small pieces of data that can be retrieved and stored as a key/value
pair. As long as you can retrieve the data you want with a direct call, this store can serve you well. In
addition, using this API doesn't require you to deal with the intricacies of asynchronous programming
and basic I/O operations, such as creating, opening, and locating files.
Search WWH ::




Custom Search