Skip to content

Support InitialDirectory and ClientGuid on FolderBrowserDialog #3512

Closed

Description

@weltkante

Is your feature request related to a problem? Please describe.

The modernized FolderBrowserDialog does not expose relevant native API, it just got retrofitted into the API for the old dialog. This leads to problems like described in #3464

  • It does not support setting the initially displayed folder. This was not relevant for the old dialog because it only had a single tree view with a single selection, so you could set the initial folder by setting the initial selection. The new dialog has a separate textbox to enter a full path and this is used for the initial selection. In some cases the native dialog will derive the initial folder from the selection but not in all cases, in particular drive roots will just fill the textbox and not set the initial folder. This leads to poor end user experience.

  • It does not support setting a ClientGuid like file open and save dialogs. This is because the old dialog had no such concept, but upgrading to the modern dialog this is necessary. This guid is used to specify context under which Windows should remember the last used folder. For example a "select folder for build output" would use a different guid than "select folder for logfiles" and allow to remember two distinct "recently used folders" depending on the context the dialog is used.

Actually those features are already available on the FileDialog base class, but for historic reasons FolderBrowserDialog just inherits CommonDialog. This can't be changed without breaking binary compatibility for running .NET Core 3.1 applications on a .NET Core 5.0 runtime, so the next best solution is duplicating the relevant FileDialog properties to FolderBrowserDialog.

Describe the solution you'd like and alternatives you've considered

Expose the relvant native API, taking FileDialog as precedence:

class FolderBrowserDialog 
{
    [DefaultValue("")]
    [SRCategoryAttribute("CatData")]
    [SRDescriptionAttribute("FDinitialDirDescr")]
    public string InitialDirectory { get; set; }

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [Localizable(false)]
    public Guid? ClientGuid { get; set; }
}

Will this feature affect UI controls?

Yes, this exposes a new property at design time, it needs to follow the usual process of annotating the properties with attributes, if the same localization as FileDialog is reused (as in the API suggestion above) then no new localization is required though. In either case everything is covered by type descriptor infrastructure and the designer itself does not need to do any special handling.

Activity

  1. added
    api-suggestion
    on Jun 26, 2020
  2. weltkante commented on Jun 26, 2020

    @weltkante
    ContributorAuthor

    When implementing this there is desire to make special shell paths like "my computer" work, otherwise a secondary API would be required. Since FileDialog.InitialDirectory doesn't seem to currently work anyways (#3513) maybe this can be supported without adding new API.

  3. added
    design-discussion
    enhancement
    on Jul 2, 2020
  4. added this to the Future milestone on Jul 2, 2020
  5. added
    api-ready-for-review
    and removed
    api-suggestion
    on Dec 4, 2020
  6. RussKie commented on Dec 4, 2020

    @RussKie
    Contributor

    The similar work has been done in #2858 for FileDialog type.
    Marking as "ready for review".

  7. modified the milestones: Future, 6.0 on Feb 24, 2021
  8. added
    api-approved
    and removed
    api-ready-for-review
    on Mar 4, 2021
  9. terrajobst commented on Mar 4, 2021

    @terrajobst
    Contributor

    Video

    • Looks good as proposed.
    namespace System.Windows.Forms
    {
        public partial class FolderBrowserDialog 
        {
            [DefaultValue("")]
            public string InitialDirectory { get; set; }
    
            [Browsable(false)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [Localizable(false)]
            public Guid? ClientGuid { get; set; }
        }
    }
  10. removed their assignment
    on Mar 4, 2021
  11. removed
    design-discussion
    on Mar 4, 2021
  12. RussKie commented on Mar 4, 2021

    @RussKie
    Contributor

    @weltkante would you like to have a go at implementing it?

  13. ghost added
    🚧 work in progress
    on Mar 9, 2021
  14. ghost removed
    🚧 work in progress
    on Mar 24, 2021
  15. removed this from the 6.0 milestone on May 17, 2021
  16. ghost locked as resolved and limited conversation to collaborators on Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions