Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Open File Dialog to Select a Folder [duplicate]

Possible Duplicate:
How do you configure an OpenFileDIalog to select folders?

I'm using C# and I want to completely avoid SelectFolderDialog to select a folder. Instead, I want to use something closer to a OpenFileDialog just to select a folder.

For a more visual example, I'm looking for something close (if not exactly) like the following: http://i44.tinypic.com/x38tx1.png

enter image description here

Any ideas?

like image 691
Demasterpl Avatar asked Feb 10 '12 12:02

Demasterpl


1 Answers

The folder selection dialog of Windows Vista looks quite similar to what you want. Unfortunately, .NET's FolderBrowserDialog shows the old Windows-XP-like dialog, which you want to avoid.

To access this Vista-style dialog, you can either

  • use some third-party .NET library (e.g. Ookii.Dialogs),

  • use the relevant Windows API calls or

  • use the Windows API Code Pack:

      using Microsoft.WindowsAPICodePack.Dialogs;
    
      ...
    
      var dialog = new CommonOpenFileDialog(); 
      dialog.IsFolderPicker = true;
      CommonFileDialogResult result = dialog.ShowDialog();
    

    Note that this dialog is not available on operating systems older than Windows Vista, so be sure to check CommonFileDialog.IsPlatformSupported first.

like image 121
Heinzi Avatar answered Nov 12 '22 15:11

Heinzi