Hey, it's a cool idea! And, since it seemed so doable, I tried it with my Raspberry Pi as well.
Here's how you could find and scan for image files on a USB stick:
Begin by adding the "Removable Storage" capability to your app:
- open Package.appxmanifest
- navigate to the Capabilities tab,
- and, ensure the "Removable Storage" option is checked.
This will basically allow your app to access files from USB devices.
But, because Universal Applications can only enumerate or read or modify file types that have been declared explicitly in the manifest under "File Type Associations", once again:
- open Package.appxmanifest,
- navigate to the Declarations tab,
- select "File Type Associations",
- and, hit Add.
Now, just fill in the fields on the right-hand pane according to all the file types that your app wants to support(check MSDN for more details).
Then, you'll be able to enumerate removable drives and their sub-files/folders as shown in the these examples. Let's say, for instance, if you wanted to enumerate top-level files (I'm using C#):
var drives = await Windows.Storage.KnownFolders.RemovableDevices.GetItemsAsync();
foreach (var drive in drives)
var files = await drive.GetFilesAsync();
Note: Only sub-folders and explicitly associated file types will show up.
Here's how you could load an image from a file:
Since you can't load a file directly from a file:// URI, you could go via a StorageFile and stream instead, something like this for example:
var file = await StorageFile.GetFileFromPathAsync(@"E:\test.png");
using (var stream = await file.OpenAsync(FileAccessMode.Read))
var bmp = new BitmapImage();
ImageControl.Source = bmp;
For exiting the application:
App.Current.Exit(); seemed to work just fine for exiting the app in my case. It was followed by that weird progress spinner symbol that usually indicates messages like "Please wait while your device is being set up" or "Please wait while we save your progress" and that annoyingly lingered on for a while.