C# Dialog to select multiple files AND folders [duplicate]

狂风中的少年 提交于 2019-12-12 13:27:01

问题


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!


回答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?




回答2:


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!



来源:https://stackoverflow.com/questions/12909640/c-sharp-dialog-to-select-multiple-files-and-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!