0

I want to know is there any API which I can use to select both file and/or folder in C#.

I have read some docs where people are suggesting to write your own wrapper class and override the properties of both OpenFileDialog and folderbrowserdialog. But I don't want to do that. Does microsoft provide any such APIs which I can use ?

rsgeeks184
  • 21
  • 6
  • No there is no default control which you can do both. Can you explain your problem in a more detailed way? – Hasan Emrah Süngü Oct 14 '20 at 06:02
  • AFAIK, these are the only options you have. – Zohar Peled Oct 14 '20 at 06:04
  • It's possible, but you'll have to use extra code. This is a *Windows* dialog, not a .NET dialog. To customize it, you need to specify the appropriate attributes through the appropriate interfaces. I suspect you already found answers about `IFiledialog` and `FOS_PICKFOLDERS `. Well, that's the solution – Panagiotis Kanavos Oct 14 '20 at 06:04
  • @ZoharPeled the OS dialog can be adapted to pick folders through Win32 calls, but I suspect the OP doesn't like that. It's the only way though – Panagiotis Kanavos Oct 14 '20 at 06:06
  • There is nothing in .NET. Not that Stack Overflow is the place to ask for directions to a documented API anyway. But, see duplicate for how to access the unmanaged API that allows this. – Peter Duniho Oct 14 '20 at 06:06
  • @PeterDuniho that's not a good duplicate at all. It doesn't explain anything. If you want to mark a duplicate [this one is far better](https://stackoverflow.com/questions/4136477/trying-to-open-a-file-dialog-using-the-new-ifiledialog-and-ifileopendialog-inter) and shows that the relevant interfaces were added in Vista/Win7 and *probably* are available through other classes. That particular duplicate though isn't helpful – Panagiotis Kanavos Oct 14 '20 at 06:09
  • @PanagiotisKanavos: the duplicate I selected first has plenty to go on, for the enterprising developer. Your suggestion is a completely different question; even if there is some code in it that could be applicable, it doesn't address _this_ question specifically. And frankly, it was completely unreasonable of you to reopen this question. You can feel free to _edit_ the duplicates list, but this question is a duplicate of the one I already marked it as, as well as https://stackoverflow.com/q/11624298 and https://stackoverflow.com/q/11628021. There's no reason to keep it open. – Peter Duniho Oct 14 '20 at 06:13
  • @PeterDuniho not at all. In fact, I did find that question while looking for duplicates, which lead me to IFolderDialog and far better duplicates. That's when I remembered trying to use the new OS dialog boxes in the past, which are *not* what `OpenFileDialog` provides. If the Windows Compatibility pack was still available, answers suggesting to use it would be the best option – Panagiotis Kanavos Oct 14 '20 at 06:14
  • @PanagiotisKanavos: You admit that this is a duplicate, and yet you reopened the question? How does that make any sense whatsoever? You are misusing your privilege. – Peter Duniho Oct 14 '20 at 06:15
  • No. I said your duplicate was a bad one. And since you didn't reopen, I did so myself. Perhaps someone else will find a better duplicate that those showing how to create a wrapper for `IFolderDialog`. Or perhaps the only solution is the duplicate suggesting to use the Ooki dialogs. – Panagiotis Kanavos Oct 14 '20 at 06:15
  • A duplicate to something that simply says "read the interface docs" is definitely *not* a good one – Panagiotis Kanavos Oct 14 '20 at 06:17
  • @PanagiotisKanavos: if you disagree with the duplicate, you are free to _add_ a new one to the list. But reopening a question that you yourself agree is a duplicate of existing questions on the site is completely wrong. Please behave better. You should only reopen a closed question when you believe the question should in fact be _opened_. That is not the case here. – Peter Duniho Oct 14 '20 at 06:20
  • @rsgeeks184 you *can't* avoid using either interop or using the Vista interfaces like IFileDialog. Lots of duplicate questions show how to do one or the other, but a practical solution would be to use a library like the [Ooki dialogs](https://stackoverflow.com/a/511161/134204), perhaps directly from NuGet. Using the Vista interfaces directly is *complicated* – Panagiotis Kanavos Oct 14 '20 at 06:26

0 Answers0