Doing a spike yesterday I had the need to use OpenFileDialog to browse and select an existing file. The problem was that I placed the files on the device root. And oops! the Windows Mobile implementation of the OpenFileDialog, this is not a .Net Compact Framework limitation, doesn't allow the user to browse the root. Actually, it doesn't allow the user to browse the whole file system, it just let you browse My Documents subfolders and Storage cards. Very bothering in some cases.
Indeed, this is not the first time I have to deal with it. An I thought I should be just one of many developers with the same problem. So I decided to implement a custom OpenFileDialog in c# targeting PocketPC, but easily portable to Smartphone, and customizable and extensible as well. Wow! I think I should have said that first of all, it's a very simple piece of code. And that's its best feature. You can use it as a starting point.
I've not implemented the full Filter feature of the original OpenFileDialog because I think it's not a common scenario on mobile development and it make the UI overcrowded. Instead, the Filter property of my MobilePractices.OpenFileDialogEx implementation, is just a search pattern.
The MobilePractices.OpenFileDialogEx looks this way:
The dialog title can be changed as you wish thru the Text property. At the top of the screen, you can see a ComboBox which can be used to quickly go back to an specific folder.
Taking a look at the first snapshot you can notice that I'm identifying storage cards with a different icon. To identify a storage card you can check if the FileInfo.Attributes for it are Directory and Temporary.
if ((info.Attributes & (FileAttributes.Directory | FileAttributes.Temporary))
== (FileAttributes.Directory | FileAttributes.Temporary))
How to continue with this is up to you. You can add an InitialDirectory property, or some way to keep the current path along the application run, or a modified version which allows you to select a directory instead of a file. Or you can take the code and port it to smartphone. Probably I'll do that soon in a new post. Once more, this is just a starting point!
Here you have the source code including a sample application: