User Content Files and Windows 8 Metro Application - Part 1

This post introduces a few concepts which can help you when working with user content files in Metro Applications. Next post will focus on the code and a demo. The post is full of concepts and theory and you may be a person who like to see code more than the concepts. However, it is necessary to understand the basic concepts before starting a code demonstration. I promise. Next post will have code, code and nothing else. Read further..

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
  1. From the user content files located on a machine, removable storage, or a network drive.
  2. From the isolated storage which is local to application (APP DATA)
  3. From the Web. (Through WCF, OData Service etc)
  4. 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..

We can create metro applications using C# / VB.Net for the business logic and XAML for the User Interface. Also, if you are from a web background, you can create a metro app just with JavaScript for business logic and HTML for the User interface. No more disappointment!

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.

Popular posts from this blog

Image upload using JQuery + Uploadify + ASP.Net Custom Handler

Generating reports with Templater, MS Word & C#

Creating a cool Microsoft Word Report for listing Scientists with Templater and C# Generic List