2

I want to show a dialog (like as OpenFileDialog) to browse for folders and also the files. My windows-forms app is to auto-rename image files in a folder (and optionally all sub folders in it). When user want to select the path, he or she may choose the first file in a folder, OR, choose a parent folder to process all files in that folder and sub-folders.

It is important to see the files in each folder such that user can ensure the proper folder is chosen. It would be nice to be able to see image thumbnails as we can do by OpenFileDialog in .Net.

There are several questions in SO (like this and this) but none of them work completely as described above! What I have tested:

  • The built in OpenFileDialog does not let to select a folder. There is some tricky hack that suggest setting the FileName to something like as "Folder Selection." or "Select..." before calling ShowDialog() method. It works in some scenarios but it has some buggy behavior (at least in Windows 10) for example if user press the back or up buttons (or choose one of mid folders from the path bar at top), the new location can't be chosen by pressing the Open button.
  • The WindowsAPICodePack (and CommonOpenFileDialog described in this answer) does not show files when IsFolderPicker is set to true .
  • The Ookii.Dialogs (VistaFolderBrowserDialog) does not show files when browsing folders.
S.Serpooshan
  • 7,608
  • 4
  • 33
  • 61
  • [Select file or folder from the same dialog](https://www.codeproject.com/Articles/44914/Select-file-or-folder-from-the-same-dialog). To adapt. – Jimi Jul 30 '19 at 10:07
  • @Jimi That very old code actually use the same method as first item I mentioned in my question (use standrad `OpenFileDialog` with some special initial value like as "Folder Selection." for FileName property before calling the `ShowDialog()` method). So the same problem occur: it has some buggy behavior (at least in Windows 10) for example if user press the back or up buttons (or choose one of mid folders from the path bar at top), the new location can't be chosen by pressing the Open button. – S.Serpooshan Jul 30 '19 at 11:28
  • In all applications which I know, the option for opening a file is different from opening a folder and they show different dialogs. For example take a look at Visual studio File → Open which has options for opening a file or opening a folder. Windows common file dialogs doesn't have builtin support for the feature which you described. I advise following the standard designs of Windows and use different dialogs for files and folders. Otherwise you need to roll your own with/without help of Windows common dialogs. – Reza Aghaei Jul 31 '19 at 14:59
  • @RezaAghaei Thanks for your comment reza, but at least, I wish to show also the Files in each folder when user browsing for a Folder. This is important to ensure the proper folder is chosen and you don't rename the files again when they are already processed! – S.Serpooshan Aug 03 '19 at 04:32

0 Answers0