Jul
21
2008

C#: File Dialog for the Compact Framework



Comments available as RSS 2.0

When Microsoft were deciding what to include in the .NET Compact Framework, they decided to restrict the OpenFileDialog and SaveFileDialog to the My Documents directory. There are plenty of reasons you’d need to choose a file outside of My Documents, so I coded a new file chooser from other components.

FileDialog for .NET Compact Framework

The dialog is just a form with a ComboBox which shows the current directory and all of it’s parents, a ListView which shows the files and directories in the current directory, and a text box to show the selected file.

Instantiate it with either the default constructor or a directory and file to show on startup.

FileInfo dbFile = new FileInfo("\\Storage Card\\Somefile.txt");
Lime49.OpenFileDialog dlg = new Lime49.OpenFileDialog(dbFile.DirectoryName, dbFile.Name);
dlg.Filter = "*.txt";
dlg.ShowDirectory(dbFile.DirectoryName);
dlg.ShowDialog();
MessageBox.Show(dlg.SelectedFile);

The selected file is available through the SelectedFile property, and the filter doesn’t work the same way as standard FileDialogs, it uses a standard wildcard pattern to list files.

Download Lime49.OpenFileDialog
Also published on CodeProject

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Comments

Leave a Comment

Login using OpenID or enter your details below to leave a comment.

OpenID
Anonymous


Comment

Powered by WP Hashcash