Share via

How to enhance OpenFileDialog() to choose folder instead of files

Ajay Gera 50 Reputation points
2025-05-16T13:59:43.04+00:00

Can we enhance OpenFileDialog() to choose folder instead of files?

Currently I am using FolderBrowserDialog dialog to select folder from the system using c#.

But I am looking, UI which is provided by OpenFileDialog as shown in attached file.

Or is there any other way to achieve UI similar to OpenFileDialog() in C#?

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Castorix31 91,871 Reputation points
    2025-05-16T14:27:17.2566667+00:00

    Or is there any other way to achieve UI similar to OpenFileDialog() in C#?

    With IFileDialog and FOS_PICKFOLDERS

    (I had posted a test sample in WinUI 3 C# (WinUI3_IFileDialog), nearly same code for WinForms)

    Was this answer helpful?

    0 comments No comments

  2. Michael Taylor 61,221 Reputation points
    2025-05-16T14:21:15.71+00:00

    FolderBrowserDialog is the correct approach. It is standardized and is what WIndows users expect. You didn't really clarify why FolderBrowserDialog isn't what you want to use so I'm unclear what problem you're trying to solve by using the OpenFileDialog instead.

    As for whether you can use OpenFileDialog instead, technically yes, it is just confusing. I use one app where I need to select a folder to scan. Their approach is to use the OpenFileDialog to have you select a file. Then they ignore the file you selected and just use the folder it was defined in. This is basically what you're asking for.

    The problem with this approach is that it requires a user to have a file in the folder they want to select. Without a file then there is nothing to select which is what the OpenFileDialog requires. Whether that is an issue or not depends on your app.

    You could also argue that you could use SaveFileDialog. The advantage here is that a file doesn't have to already exist. But the user will need to specify a (non-existent) file in order to dismiss the dialog.

    Honestly, for consistency, you should stick with FolderBrowserDialog.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.