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

Ajay Gera 45 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#?

C#
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.
11,487 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 59,566 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.


  2. Castorix31 89,451 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)

    0 comments No comments

Your answer

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