directory selection component in C#
-
4 ways to enable the latest C# features
-
Thread: Save FolderBrowserDialog selection to file (config.txt)?
share-icon
It's real simple to use the built-in Settings functionality.
To add a setting, just right click on your forms project in the solution explorer and choose, "Properties".
On the left, click on the Settings tab.
Enter a new setting (I called mine 'MySavedFolder').
Choose the type and visibility (User or application). I chose User.
Give the setting a default value (I used 'default value').
Next, wire up the setting in the forms code. I created a simple test form with an textbox and a save button.
In the form editor, double click on the button to create a button handler.
Next, wire up the setting.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Retrieve the settings and load it into the textbox
textBox1.Text = Properties.Settings.Default.MySavedFolder;
}
private void saveButton_Click(object sender, EventArgs e)
{
// Save the value from the textbox into the settings.
Properties.Settings.Default.MySavedFolder = textBox1.Text;
Properties.Settings.Default.Save();
}
}
-
How to use OpenFileDialog to select a folder?
this link contains lot of good info. all kinds of component need to take a look and play around it.
-
.NET Win 7-style folder select dialog
-
Common dialog classes for Windows Forms applications
-
RichTextBox Class
-
FolderBrowserDialog Class
-
How to: Choose Folders with the Windows Forms FolderBrowserDialog Component
-
FolderBrowserDialog In C#
-
C# FolderBrowserDialog Control
-
Let the user select a folder in C#
The second useful technique is that the program saves the user’s selection between runs. At design time I created a setting named Directory. To create a setting, double-click the Properties entry in Solution Explorer and go to the Settings tab.
When it starts, the program uses the following code to load the value saved in this setting.
// Restore the saved directory.
private void Form1_Load(object sender, EventArgs e)
{
txtDirectory.Text = Properties.Settings.Default.Directory;
}
The program uses the following code to save the current selection when the form closes.
// Save the current directory.
private void Form1_FormClosing(object sender,
FormClosingEventArgs e)
{
Properties.Settings.Default.Directory = txtDirectory.Text;
Properties.Settings.Default.Save();
}
-
Browse for a Folder in C# Winforms
-
Example for FolderBrowserDialog in C#
-
C# OpenFileDialog and FolderBrowserDialog to select Files & Folder
-
Winform : How to use Folder and Open File Dialog Controls using C#
-
Set InitialDirectory for FolderBrowserDialog
-
How to Build a 'Folder Watcher' Service in C#
.