When we are working on Windows 8 Metro Apps, we have a wide range of options when choosing the data source for our apps. A metro application can access data
- From the user content files located on a machine, removable storage, or a network drive.
- From the isolated storage which is local to application (APP DATA)
- From the Web. (Through WCF, OData Service etc)
- From other applications if they expose.
And by the time I am writing this post, Microsoft has introduced the Azure Mobile services. Now, Windows 8 Metro Apps for PC & Mobile can access data from the azure cloud and the data can be in structured format. I will write about this in a separate post in near future.
Metro Apps can access certain file system locations, like the app install directory, app data locations and the Downloads folder by default. Apps can also access additional locations through the file picker or by declaring capabilities.
Metro apps can access the user files located in Windows Library. To a windows library, user can add documents, pictures and videos. Also users can add additional content locations which can be of a disk, network drive or a removable storage and the library then acts as a central repository for all the files and folders you mapped. Your metro app can access the library by just declaring a capability in the manifest of the application. When your Metro app is installed by users, it asks them to provide permission to access the library. Also, in cases where we do not want our apps to access the library directly, we can display the file pickers which allows users to select files from different locations of user's computer.
Windows 8 makes it very easy to work with files in a location transparent manner. You work with the local files, network files and the web files in the same way with the same windows storage API.
The StorageFile & StorageFolder classes of the Storage API abstracts away the physical locations. The Storage File can represent a file on the local machine or a file on the cloud and similarly a Storage folder may be a physical folder on the machine or a virtual folder representing a windows library or a group of files.
Now, to access a top level folder within our Metro Application, we need to provide a reference to it. For example, we can write the code like
StorageFolder picLibrary = Windows.Storage.KnownFolders.PicturesLibrary;
The KnownFolders class Provides access to common locations that contain user content. The class is static and cannot be instantiated. You must Call the methods directly instead. Also, In order to access the folder and libraries represented by the properties of this class, you must declare the necessary capabilities in your app manifest as I mentioned..
In the next post, we shall create a Metro Application for displaying images from the windows pictures library. Just install the prerequisites Visual Studio 2012 (at least a express edition) and the Windows 8 operating system (a preview version at least) and get ready for the action.