0

I was looking for and Open Folder Dialog (wpf). I get the Ookii dialogs for wpf and I use VistaFolderBrowserDialog. (I don't like the FolderBrowserDialog of Windows Forms).

I save the "last open folder". So the next time the user open this VistaFolderBrowserDialog the Initial Folder is the "last one" I saved.

...
//Save the new actual folder
MyProject.ProgramConfigurationFile.Instance.OpenFolderPath = System.IO.Path.GetDirectoryName(folderDialog.SelectedPath);

VistaFolderBrowserDialog has the property => RootFolder:

public Environment..::..SpecialFolder RootFolder { get; set; } But it is a SpecialFolder type.

So I am looking for a way to set my String OpenFolderPath to the RootFolder property.

VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();
folderDialog.Description = "Please select the folder";
folderDialog.UseDescriptionForTitle = true;
if ((bool)folderDialog.ShowDialog(this))
{
     //Get the last open folder saved (if exist).
     if(!String.IsNullOrEmpty(MyProject.ProgramConfigurationFile.Instance.OpenFolderPath))
     {
         folderDialog.RootFolder = Environment.SpecialFolder. //I would like to set OpenFolderPath
     }  
}

Other Folder Browsers are also welcome.

Thank you very much.

Beatriz
  • 3
  • 2
  • Do you need the special folder path as a full string? If you do try this var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); – Ryan Thomas Feb 19 '20 at 11:56
  • Thank you. The other way around. Since the property is SpecialFolder type, I would need my path String as a SpecialFolder – Beatriz Feb 19 '20 at 12:00

2 Answers2

-1

I did not know before now Ookii dialogs, but after a little search and knowing how common Open Folder Dialog works i suggest that you set your lastOpenFolder to the SelectedPath property

folderDialog.SelectedPath = MyProject.ProgramConfigurationFile.Instance.OpenFolderPath;

But this must be done before folderDialog.ShowDialog(this) showing the dialog.

So it should look something like

VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();
folderDialog.Description = "Please select the folder";
folderDialog.UseDescriptionForTitle = true;

if(!string.IsNullOrEmpty(MyProject.ProgramConfigurationFile.Instance.OpenFolderPath))
    folderDialog.SelectedPath = myProject.ProgramConfigurationFile.Instance.OpenFolderPath;

if ((bool)folderDialog.ShowDialog(this))
{
    string newSelectedFolderPath = folderDialog.SelectedPath;
    // Use new folderPath
}

Let me know if this solves it.

I hope I was usefull.

Federico Rossi
  • 415
  • 5
  • 11
-2

Simple answer from 2023 for WPF for future people who hate sifting through stackoverflows endless incorrect answers and needless fluff.

This answer uses Ookii.Dialogs.WPF NuGet package you can install from right inside visual studio. At the top left click Project -> Manage NuGet Packages... -> Go to browse tab and search OOkii.Dialogs.Wpf then install it. Now this code will work. :)

You can directly copy paste this.

VistaFolderBrowserDialog FolderSelect = new VistaFolderBrowserDialog(); //This starts folder selection using Ookii.Dialogs.WPF NuGet Package
FolderSelect.Description = "Please select the folder"; //This sets a description to help remind the user what their looking for.
FolderSelect.UseDescriptionForTitle = true;    //This enables the description to appear.        
if ((bool)FolderSelect.ShowDialog(this)) //This triggers the folder selection screen, and if the user does not cancel out...
{                
    TextBoxGameFolder.Text = FolderSelect.SelectedPath; //...then this happens.
}
    ```
Dawnbomb
  • 1
  • 1
  • 5