3

Possible Duplicate:
Required Dialog for selecting Multiple Files and Folders .NET

I am searching for a dialog that'll allow the user to select multiple files and folders, simply in one dialog. I've searched the internet but had no good luck finding something that'd do the trick, only something that applied for C++.

Please correct me if there IS already an answer out there, because I have seriously spent time trying to find a solved question for it already.

I would appreciate the help!

Community
  • 1
  • 1
Infernus
  • 53
  • 1
  • 2
  • 8
  • Thanks for the replies, but an OpenFileDialog does not allow folders to be selected. – Infernus Oct 16 '12 at 07:40
  • The second link answers your question; the question is an exact duplicate. – Dan Puzey Oct 16 '12 at 07:46
  • Unfortunately, it does not proceed my requirements. These dialogs can only select multiple files, not multiple files **and** multiple folders. Thanks for your advice though. – Infernus Oct 16 '12 at 08:26
  • @Infernus, did you ever find a solution to you problem? I'm looking for a similar solution. – Dan Cundy Feb 09 '16 at 21:41

2 Answers2

1

See the OpenFileDialog::Multiselect property, from the docs:

Gets or sets a value indicating whether the dialog box allows multiple files to be selected.

To get the list of files selected you should use the OpenFileDialog::FileNames property.

Adding style OFN_ALLOWMULTISELECT, see this Article Multiple File Selection Without Any Extra Code

CodeProject Article: SelectDialog - A Multiple File and Folder Select Dialog

ADDED: See this added sample code for Multiple Files Selection in C#:

OpenFileDialog d = new OpenFileDialog();
d.Filter = "All files|*.*";
d.Multiselect = true;
if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    foreach (string fileName in d.FileNames)
    {
       // ... do something ...
    }
}

For Multiple Folder selection,

You can use TreeView control by populating it with the Directory structure using the below reference:

Populate TreeView with file system directory structure

Secondly, you can allow multiple selection using SelectedNodes of TreeView Control to select multiple folders.

C# TreeView with multiple selection

FolderBrowserDialog Control

Hope this will help you!

Community
  • 1
  • 1
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
  • Thanks for the advice. The SelectDialog you linked is written in C++. I have no idea how I could ever use this in C#. All I could think of is creating a class library, but I've already tried this and miserably failed due to very limited knowledge of C++. – Infernus Oct 16 '12 at 08:20
  • 1
    Again, this does only allow multiple files to be selected. I want it to allow multiple files **AND FOLDERS** to be selected. – Infernus Oct 16 '12 at 08:31
  • Try to use different filter as per your requirement, by the way this code should work 100%. Replace this line d.Filter = "All files|*.*"; and select multiple by pressing Ctrl key. – Furqan Safdar Oct 16 '12 at 08:37
  • I appreciate your help, but it still does not allow me to select folders too. Actually, it does allow me to select them, but it does not show up in the selected items list. – Infernus Oct 16 '12 at 08:44
  • This solution is primarily for files and NOT for folders, Can't you still select multiple files using this code? – Furqan Safdar Oct 16 '12 at 08:47
  • Once again check my edited code – Furqan Safdar Oct 16 '12 at 08:55
  • I understand the code, but my point is that I **can** select them in the browser, both files and folders. But when looping through Dialog.FileNames, the folders are **>>not<<** in there at all, and that is what I need. – Infernus Oct 16 '12 at 08:59
  • There is no OpenFolderDialog control rather OpenFileDialog which works for files only. If you check my edited answer you may find the way to create a OpenFolderDialog using TreeView.SelectedNodes for multiple folder selection. What else you need? I'm sorry, there is no ready-made control provided by Microsoft for folders. – Furqan Safdar Oct 16 '12 at 09:03
  • Hmm, now that you speak of 'tree', yes it could be what I want. Do you know any good treeview kind of file/folder select dialog? I can't find it anywhere on google, and I'm sure I've seen it before. I hope you know what I mean, it could help me out. – Infernus Oct 16 '12 at 09:20
  • First of all it is better to have two different controls rather having one, so that you know that one control will provide files and other provides folders. I will be sharing the Folder Control reference soon by self implementing it for you. – Furqan Safdar Oct 16 '12 at 09:31
  • My answer didn't help you in any way? – Furqan Safdar Oct 17 '12 at 17:43
1

Have you tried Ookii.Dialogs?

It should match all your requirements, or be at least a very good starting point.

Go through this also : C# - How to customize OpenFileDialog to select multiple folders and files?

Community
  • 1
  • 1
Okky
  • 10,338
  • 15
  • 75
  • 122
  • Hello, thanks for your help. I am now trying Ookii.Dialogs. It works, but not the way I want it to. I want to be able to select multiple files AND folders. Not only files, also folders. The question is the same, but the only real good answer given was using "CommonOpenFileDialog". I'll have to look into that, can't find very much information about it, not even how to create one or in where it should be located. – Infernus Oct 16 '12 at 08:22