Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PickFolders option for OpenFileDialog (minimal) #6374

Closed
wants to merge 1 commit into from

Conversation

miloush
Copy link
Contributor

@miloush miloush commented Apr 6, 2022

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 the IOpenFileDialog. 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 sets FOS_PICKFOLDERS and clears OFN_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 whole IFileDialog 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 with PickFolders will throw COMException on ShowDialog().

The bit used by OPTION_PICKFOLDERS is currently unused in both legacy and IOpenFileDialog 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 with OPTION_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

@ghost ghost assigned miloush Apr 6, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Apr 6, 2022
@ghost ghost requested review from dipeshmsft, singhashish-wpf and SamBent April 6, 2022 20:21
@ghost ghost added Community Contribution A label for all community Contributions draft labels Apr 6, 2022
@Symbai
Copy link
Contributor

Symbai commented Oct 15, 2022

@miloush Reason why this is still being a draft?

@miloush
Copy link
Contributor Author

miloush commented Apr 19, 2023

Closing in favor of #7244 which passed API review.

@miloush miloush closed this Apr 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Community Contribution A label for all community Contributions draft PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WPF alternative for WinForms FolderBrowserDialog
2 participants