Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

".RestoreDirectory" does not work

In the following code I set ofd1.RestoreDirectory as false however, the dialog opens the inital directory everytime. Is there something that I am not aware of?

private void btnMeshFile_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd1 = new OpenFileDialog();
    ofd1.Title = "Open";
    ofd1.InitialDirectory = @"c:\";
    ofd1.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
    ofd1.FilterIndex = 2;
    ofd1.RestoreDirectory = false;
    if (ofd1.ShowDialog() == DialogResult.OK)
    {
        string fileName = Path.GetFileName(ofd1.FileName);
        MeshDirectoryPath = Path.GetFullPath(ofd1.FileName).Replace(@"\", @"\\");
        txtMeshFile.Text = fileName;
    }
}
like image 889
Shibli Avatar asked Mar 28 '26 16:03

Shibli


1 Answers

From MSDN documentation of RestoreDirectory

Gets or sets a value indicating whether the dialog box restores the current directory before closing.

So this property is about restoring OS current directory.

But you, in the code also use InitialDirectory property, forcing the dialog every time start from @"c:\"; path. Remove this, and it will resolve your problem.

like image 114
Tigran Avatar answered Mar 31 '26 11:03

Tigran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!