B Bhatnagar
B Bhatnagar

Reputation: 1806

Select both files and folders using OpenFileDialog

I have researched a lot to find a suitable answer to this problem, but I am failing .

I can see multiple questions asked here and on other forums also , but no clear answer that brings a clear solution .

I want OpenFileDialog to select file/files for me as well as allow me to select folders also. eg. a. either Multiple files OR multiple folders (- most Prior) b. combination of Files and Folders (-less Prior)

I figured our similar question here ( so please don't mark it as duplicate )

Question 1 [Answer links are broken]

Question 2 [Question isn't completely asking what my requirements are.]

Please guide me through some solution . I am a novice and a learner.

Any help or pointers would be very helpful .

Thanks.

Upvotes: 11

Views: 13387

Answers (4)

user4584267
user4584267

Reputation:

var dialog = new OpenFileDialog();
dialog.ValidateNames = false;
dialog.CheckFileExists = false;
dialog.CheckPathExists = true;
dialog.FileName = "Must set default";
dialog.ShowDialog() // will allow both files and folders to be selected

Quite hack-ey.

Source

Upvotes: 3

Kurubaran
Kurubaran

Reputation: 8902

You can't select folder with OpenFileDialog as well as you can't select files with FolderBrowserDialog. But there is an open source control for .net which allows you to select both files and folders you can check it here : OpenFileOrFolderDialog

Upvotes: 3

Anirudha
Anirudha

Reputation: 32787

OpenFileDialog is used to open a file not folder

To allow selection of multiple files set Multiselect property to true.

For selecting Folder it's mentioned in the docs

If you want to give the user the ability to select a folder instead of a file, use FolderBrowserDialog.

Upvotes: 2

Frank59
Frank59

Reputation: 3261

You can create selctor "files or directories" and open standart OpenFileDialog or FolderBrowserDialog depending on user selection. Or you can create(or find) your custom file manager with options for selecting folders and files together.

Upvotes: 0

Related Questions