'How to save FolderBrowserDialog structure tree when loading the app and clicking the browsing button?

When i click the btnBrowser it will save the folderDlg.SelectedPath :

folderDlg.SelectedPath = Properties.Settings.Default.BrowseFolderDialog;
Properties.Settings.Default.BrowseFolderDialog = folderDlg.SelectedPath;
Properties.Settings.Default.Save();

Then when loading :

private void Form1_Load(object sender, EventArgs e)
        {
            textBoxFileDirectory.Text = Properties.Settings.Default.BrowseFolderDialog;
        }

It will add the content in folderDlg.SelectedPath to the textBox.

For example :

Saved folder

but now how can i save also the BROWSER button when i click the button that it will be opened at this folder D:_Images ?

This is when i pressed the BROWSE button : It's starting with the Desktop folder :

Desktop

and i want it to start by default with the D:_Images folder :

The folder it should load when clicking the browse button

I tried to do it with this line : when clicking the browse button but it's not working. Stil the opening default folder is the Desktop and not D:_Images

folderDlg.SelectedPath = Properties.Settings.Default.BrowseFolderDialog;

The code :

private void btnBrowser_Click(object sender, EventArgs e)
        {
            if (radioButtonWatchFile.Checked)
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.InitialDirectory = "c:\\";
                    openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                    openFileDialog.FilterIndex = 2;
                    openFileDialog.RestoreDirectory = true;

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        textBoxFileDirectory.Text = openFileDialog.FileName;
                    }
                }
            }

            if (radioButtonWatchDirectory.Checked)
            {
                FolderBrowserDialog folderDlg = new FolderBrowserDialog();
                folderDlg.ShowNewFolderButton = false;

                DialogResult result = folderDlg.ShowDialog();
                if (result == DialogResult.OK)
                {
                    textBoxFileDirectory.Text = folderDlg.SelectedPath;

                    folderDlg.SelectedPath = Properties.Settings.Default.BrowseFolderDialog;
                    Properties.Settings.Default.BrowseFolderDialog = folderDlg.SelectedPath;
                    Properties.Settings.Default.Save();

                    fsw = new FileSystemWatcher(folderDlg.SelectedPath);
                    fsw.NotifyFilter = NotifyFilters.Attributes
                                     | NotifyFilters.CreationTime
                                     | NotifyFilters.DirectoryName
                                     | NotifyFilters.FileName
                                     | NotifyFilters.LastAccess
                                     | NotifyFilters.LastWrite
                                     | NotifyFilters.Security
                                     | NotifyFilters.Size;

                    fsw.Changed += Fsw_Changed;
                    fsw.Created += Fsw_Created;
                    fsw.Deleted += Fsw_Deleted;
                    fsw.Renamed += Fsw_Renamed;
                    fsw.IncludeSubdirectories = true;
                    fsw.EnableRaisingEvents = true;
                    fsw.SynchronizingObject = this;
                }
            }
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source