I have a OpenFileDialog which should open up a specific path say %ProgramData% when 'Browse' clicked for the first time the user uses the application. And for all successive terms, it should open up the last used folder.
I tried:
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = "C:\ProgramData";
ofd.RestoreDirectory = true;
ofd.FileName = "";
DialogResult dr = ofd.ShowDialog();
The problem here is, it opens up "C:\ProgramData" every time, even if I change path while looking for the required file. Is there a specific property that I should set or do I have to programmatically keep track of the usage of the OpenFileDialog and set path accordingly?
Try this:
you are resetting intialdirectory to C:\ProgramData on button click
public partial class Form1 : Form
{
OpenFileDialog ofd = new OpenFileDialog();
public Form1()
{
InitializeComponent();
ofd.InitialDirectory = "C:\\ProgramData";
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = ofd.ShowDialog();
ofd.InitialDirectory = null;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With