3

it is possible to select multiple files using OpenFileDialog. (setting multiselect as true)

the question is how to select multiple files and folders at the same time?

I know what is FolderBrowseDialog, I know I should Hold ctrl or shift! :D

assume a folder contain 5 folder and 2 files, the scenario is to select for example 1 of files and 2 folders.

I don't know why people down vote this question!!

----------------- Edit --------------------

assume an OpenFileDialog, you can select as many file as you want in a folder, ok? I want something like this but with the ability to select folders too! so as OpenFileDialog return selected file names in FileNames array that dialog return something Like SelectedPaths array that contains filenames and folderpaths.

  • How exactly do you envision that such a UI should look? If the user should be allowed to select file A, B and C from folder X, then file D from folder Y, then the entire folder Z? For this kind of functionality you probably have to roll your own. – Pedery Nov 30 '10 at 17:00
  • assume a folder contain 5 folder and 2 files, the scenario is to select for example 1 of files and 2 folders. –  Nov 30 '10 at 17:02
  • @HPT: this causes some ambiguity what to do when a single folder is selected and the user presses OK. Enter the folder, or accept it as selection? (Some newer - custom? - dialogs opt for the latter, and only allow double click for navigating into the folder. Much easier to use than the ShBrowseForFolder dialog, but I'm lot entirely happy with the reliance on the mouse) – peterchen Nov 30 '10 at 17:05
  • 1
    P.S. Why the downvotes? It's a valid question IMO, even though it's probably not solvable through the common dialog implementation. – peterchen Nov 30 '10 at 17:06
  • @peterchen: double clicking a file would be a selection and double clicking a folder should enter the folder, at last you can select some folders and files using ctrl key and click open button. the dialog should return path of selected items. –  Nov 30 '10 at 17:07
  • I did not downvote this question, but it would probably help if you explain your end goal, not just the step you are stuck on. – Dour High Arch Nov 30 '10 at 17:22
  • Ah - based on your clarification, do you want to use the OpenFileDialog, but just be able to have it return a selected folder (along with files) in the results when you select both files and folders? That makes much more sense - if this is the case, I'll give rephrasing your question a crack so it's clearer to the readers. – SqlRyan Nov 30 '10 at 17:27
  • @rwmnau: yes you completely hit the point! –  Nov 30 '10 at 17:51
  • @HPT: double click is clear, but now how do I navigate into a folder without using the mouse? – peterchen Nov 30 '10 at 19:07
  • @peterchen: i dont think that is a big deal for this issue, right click button with keyboard and select open. –  Nov 30 '10 at 21:24

2 Answers2

1

I've done this in an application I built, and I ended up using a TreeView control and just mapping the hard drive into this control - each folder had a TreeNode, nested to match the folder structure, and then the files at the deepest level.

While it's memory-hungry, a user can select/de-select individual files, and it's pretty easy to automatically select/de-select all the children when somebody checks a parent folder.

SqlRyan
  • 33,116
  • 33
  • 114
  • 199
  • you mean that i start writing and implementing that for myself? –  Nov 30 '10 at 17:22
  • 1
    @HPT: I don't see why not. If you're asking for me to write the code for you, you won't get much help on the site - people here are happy to point you in the right direction, but it's still your application to develop and people aren't going to write it for you. If you need some more detail before you're able to implement something like this, please let me know what part of my suggestion is confusing and I'll clarify it. – SqlRyan Nov 30 '10 at 17:25
  • I know how to write that, asking on SO isn't mean you cant do that, maybe it is as a matter of not doing something done before or an easy way that is possible but you are not aware of it. –  Nov 30 '10 at 17:29
1

The Common Item Dialog (which replaces the Open File Name Common Dialog Box) has a few points of customization. I haven't tried, but by hooking IFileDialogEvents you should be able to change behavior as you need. (You might need to add some trickery, it was possible with an OFNHookProc in XP style file dialog)


Even though this means reading a lot of frustrating Microsoft documentation, It's preferrable over developing a custom dialog:

When copying a platform feature, you have to copy all of it.

That means e.g. pasting files through Ctrl+V, Shift+Ins or the context menu, and if that shell extension I just wrote doesn't work, I'm pissed.

peterchen
  • 40,917
  • 20
  • 104
  • 186
  • I read that and it seems to satisfy my requirements, the question now is how can I use them in C#? all samples there are written in c++. –  Nov 30 '10 at 21:54
  • A quick google doesn't turn up much, the best is this: http://stackoverflow.com/questions/4136477/trying-to-open-a-file-dialog-using-the-new-ifiledialog-and-ifileopendialog-interf. koders.com might turn up more when prodded. – peterchen Nov 30 '10 at 22:26