Asked by:

Does "Folder enumeration sample" work in a folder for which capability cannot be declared

Question

We are porting our in-house desktop app to Windows store app to take advantage of new gestures of input (touch and penstyle). The app is expected to read and visualize data files stored in a folder on a mapped network drive (e.g. Z:\data), just like
browsing photos one by one in the picture library folder. I tried the Windows 8 "Folder enumeration sample", but this sample only works in a folder for which we can declared capability in package.appxmanifest file. This controdicts the comments written in
description.html:

"This sample shows how to enumerate the top-level files and folders inside a location (like a folder, device, or network location), and how to use queries to enumerate all files inside a location by sorting them into file groups."

So we need to programmatically get a sorted list of all files of a given folder. If this feature cannot be implemented, then I am afraid there is little change to deploy Windows store version of our app in our company. Maybe we may turn to Android to
see if it is feasible, but most of us preferred Windows 8/RT. Could someone help? thank.

Wednesday, December 19, 2012 4:36 PM

All replies

How are you accessing the z:\data folder? Folder enumeration should work if the user grants access through the FolderPicker, but your app won't have access to the folder by default. Once the user grants access the first time the app can cache that access
to enumerate the StorageFile unprompted later.

How are you accessing the z:\data folder? Folder enumeration should work if the user grants access through the FolderPicker, but your app won't have access to the folder by default. Once the user grants access the first time the app can cache that access
to enumerate the StorageFile unprompted later.

We're accessing the Z:\data folder by users' opening a file (e.g. Z:\data\file1.hdf) in this folder through the FilePicker. Then users expect our app to open next files (e.g. Z:\data\file2.hdf, Z:\data\file3.hdf and so on) when they start navigating. This
is similar to viewing photos in a folder: opening a photo file in the folder through FilePicker, and then view the rest without using FilePicker.

That won't work. If the user grants you access to the file then you have access only to that file. You cannot access other arbitrary files that you don't have access to.

For what you describe you should use the FolderPicker to have the user choose the folder their files are in.

--Rob

It's too bad if that won't work. Let users navigate between files in a folder by choosing a folder through FolderPicker seems odd. I am afraid they may not accept this non-traditional Windows way to view files in their trusted folder.

That won't work. If the user grants you access to the file then you have access only to that file. You cannot access other arbitrary files that you don't have access to.

For what you describe you should use the FolderPicker to have the user choose the folder their files are in.

--Rob

We come up with a walkaround to this issue and hope it may work.

We may add an option in my app to let user select a folder that holds all their files through a FolderPicker. It makes sense since the data folder is fixed (e.g. Z:\data). In this way we get a StorageFolder object representing Z:\data (say m_RootFolder).

In our case, given a file (e.g. Z:\data\subdir1\file1.hdf) and its associated StorageFile object (say m_file), we hope to use m_RootFolder.GetFolderFromPathAsync(m_file.Path) function to obtain the deepest folder (Z:\data\subdir1) and its associated StorageFolder
object (say m_file1Folder). Finaly we call m_file1Folder.GetFilesAsync() to get the file list and do a search to find the next file of Z:\data\subdir1\file1.hdf.