PickFolders option for OpenFileDialog (minimal) #6374
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For discussion. Fixes #438. Further discussion in #4039. Previous attempt: #6351
Description
Allows developers to ask the user to select a folder, a feature known as
FolderBrowserDialog
in WinForms.This PR is the minimal code changes needed to introduce the feature. It closely reflects the underlying API design, i.e. the ability to specify
FOS_PICKFOLDERS
on theIOpenFileDialog
. This is a backwards compatible solution - no public API has been moved or removed and no existing behavior has changed.A custom option
OPTION_PICKFOLDERS
is introduced that setsFOS_PICKFOLDERS
and clearsOFN_FILEMUSTEXIST
when the dialog is prepared.New visible members
In
OpenFileDialog
:public bool PickFolders { get; set; }
Legacy behavior
Legacy code path (pre-Vista) ignores the flag and shows standard file open dialog.
Customer Impact
Without this fix, users have to either use WinForms'
FolderBrowserDialog
, resort to 3rd party libraries or re-implement the wholeIFileDialog
API. #438 is currently the top voted issue in the repository.Regression
No.
Testing
Compiled custom PresentationFramework.dll and tested in 6.0.2 x86 app that both folder browsing and file browsing works as expected.
Risk
Low - existing behavior not affected, minimal code changes. Setting
Filter
on a dialog withPickFolders
will throwCOMException
onShowDialog()
.The bit used by
OPTION_PICKFOLDERS
is currently unused in both legacy andIOpenFileDialog
API, but it might get allocated in the future. This would however not break this feature as the bits are masked out (same happened in the past withOPTION_ADDEXTENSION
).User code that processes "used" file dialogs could now be handed an instance that unexpectedly contains folders in the
FileName(s)
properties. This, however, would have to be explicitly caused using new code. Unexpected file operations on folders (i.e. trying to open them) yield IO exceptions that the existing code should be already handling./cc @ThomasGoulet73 @batzen
Microsoft Reviewers: Open in CodeFlow