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;
}
}
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.