Using HTML5/Javascript in Windows Store apps: Data access and storage mechanism (I)
Author: Roy Tian
Introduction
Windows Store app offers lots of methods for data access and storage. And this article will only focus on HTML5/JavaScript programming.
In this tutorial, we’ll go over Application Data, File API , HTML5 Web Storage, Indexed Database API and remote data access. With these you can store more data – and store it more efficiently.
Data Storage:
Application Data, when an app is installed, the system gives it its own per-user data stores for application data such as settings and files. You don't need to know where or how this data exists, because the system is responsible for managing the physical storage. Just use the application data API, which makes it easy for you to work with your application data.
Local |
Roaming |
Temporary |
Persistent data that exists only on the current device |
Data that exists on all devices on which the user has installed the app |
Data that could be removed by the system at any time |
File API, you could save app data directly in file. Windows Store App supports accessing files at local temp directory, local storage directory, and system well-known directories.
Object |
Describe |
Authority |
Windows.ApplicationModel.Package.current.installedLocation |
Get a StorageFolder which you can load data from files in your app package |
read-only |
Windows.Storage.ApplicationData.current.localFolder, roamingFolder and temporaryFolder |
Provide StorageFolder objects for your app data locations |
read-write |
Windows.Storage.Pickers.FolderPicker,FileOpenPicker and FileSavePicker |
FolderPicker |
|
Windows.Storage.KnownFolders |
Provide StorageFolder objects for the Pictures, Music, Videos, and Documents libraries, as well as Removable Storage. |
|
Windows.Storage.DownloadsFolder |
Provide a createFolderAsync method which you can obtain a StorageFolder in that location |
|
Windows.Storage.StorageFolder.getFolderFromPathAsync |
Return a StorageFolder for a given pathname only if your app already has permissions to access it |
|
Html5 web Storage and Indexed Database API. All these are HTML5 specific feature. And this is also only supported by Windows Store app built with HTML/JavaScript (C#/VB.NET and C++ based app cannot benefit from this).
Web Storage |
Indexed DB |
Storing key-value pairs on the client side |
IndexedDB has a 250MB limit per app and an overall system limit of 375MB on drives smaller than 30GB, or 4% (to a maximum 20GB) for drives over 30GB |
Carrying out multiple transactions in different windows at the same time |
IndexedDB on Windows 8 has no complex key paths—that is, it does not presently support multiple values for a key or index |
Storage spans multiple windows |
|
Can't store a larger amount of data, recommends a limit of 5 MB |
|
Remote Data Access:
Generally, the data source will be Microsoft SQL Server or other large database. JavaScript can’t access that directly, but you could use WinJs.xhr or component.
- You could write a web service or some handler to handle the data read/write, and then call that from windows store app with WinJs.xhr post or get.
- Writing the data read/write with c# and wrapping that as component, and then using in windows store app.