Skip to content

VistaFolderBrowserDialog: Set InitialDirectory (not SelectedPath) #35

Open
@nzain

Description

@nzain

The VistaFolderBrowserDialog does not have an InitialDirectory property (like the open/save file variants do). The SelectedPath property sounds similar, but actually navigates to the parent directory and sets the given directory name as input for the textbox at the bottom.

Unless (hidden feature) you append a trailing backslash or slash. In that case, the dialog opens in the given path and nothing is selected.
I guess this only works because Path.GetDirectoryName(..) is tricked into a different result here: https://github.com/augustoproiete/ookii-dialogs-wpf/blob/d157189c795d4fdb500662bde8ad328d7d3eb602/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs#L280-L290

Whatever the implementation details, it would be good to have an explicit API that allows to set the initial directory.

Additional remarks:

  • Path.DirectorySeparatorChar (backslash) works
  • Path.AltDirectorySeparatorChar (slash) works, too but I'm on windows 10. Not sure if that makes any difference.
    My code looks like this for now:
string initialDirectory = string.IsNullOrEmpty(dir) 
        || dir[dir.Length - 1] == Path.DirectorySeparatorChar
        || dir[dir.Length - 1] == Path.AltDirectorySeparatorChar
    ? dir
    : dir + Path.DirectorySeparatorChar;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions