Chapter 15. Working with files
This chapter covers
- Listing files and folders
- Programmatically accessing files
- URI standards for file access
- Using and creating file pickers
Quick! Look at all the applications you currently have open on your computer. How many of them have files open? Those files may be web pages from a remote location, a custom database of email items, a document, a music file, maybe more. Even games need to access data files both for saved games as well as for just general game data.
Most apps need to work with files either as native data for the app or as something they consume and provide value by working with, like music files. Unlike web apps and plug-ins, native apps can be given more access to the filesystem, to load a number of different types of data files. As you’d expect, WinRT XAML apps can use a number of different approaches to working with these files.
The first approach we’ll explore in this chapter is also the most involved: working with the StorageFile and StorageFolder classes. We’ll use these classes, as well as a few other helper classes, to list files and to create new files. Along the way, we’ll take a look at how to use multiple data templates to show files and folders differently in a single ListView.
Once we’ve worked out how to programmatically access files, we’ll take a brief look at the URI syntax for the different file locations. Windows 8 adds a number of different URI schemes that you can use from markup as well as from code.