0

for my C# WPF project I need a Folder Selection Dialog. Because it is neccesary that the user is able to see the content of the folders while browsing to choose the correct one, I am not able to use the Win Forms FolderBrowserDialog, which does not show the content. External packages might be also problematic.

I first thought this will be an easy task, keeps me struggeling for quite a while now.

Has anybody a great idea to implement it without creating my own usercontrol.

Thanks al lot in advance

lloyd
  • 1,683
  • 2
  • 19
  • 23
JustMe
  • 366
  • 1
  • 4
  • 14
  • See [here](http://stackoverflow.com/questions/31059/how-do-you-configure-an-openfiledialog-to-select-folders)? – James Aug 18 '15 at 10:10
  • Thanks, I will look into it. – JustMe Aug 18 '15 at 10:26
  • A simple usercontrol with treeview for folders and some listview (in details mode?) to show files should do. For alternatives see [here](http://stackoverflow.com/q/12461016/1997232). – Sinatr Aug 18 '15 at 10:26

1 Answers1

0

A "solution" without external packages, without rolling your own control and without P/Invoke-stuff, but more of a horrible workaround:

//using System.Windows.Forms;

OpenFileDialog ofp = new OpenFileDialog();
ofp.FileName = "The file will be ignored";
ofp.CheckFileExists = false;
ofp.CheckPathExists = true;
ofp.ValidateNames = false;

Simply put, a non-existing file with the name The file will be ignored will be selected from the dialog. As CheckFileExists is false, this won't be a problem and you can just read the chosen directory.
In other words: the user can select any file he/she wants.

I don't recommend using this. It's quite horrible (in style and for the user), but this is the most simple way to achieve what you want. Personally, I would go all the way and implement my own control or - even better - use a third-party control. There are a few out there who do this.

There is no support for this out-of-the-box. With the standard dialogs you can either see files, but not select folders or the other way round.

KeyNone
  • 8,745
  • 4
  • 34
  • 51