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
RestoreDirectorySo this property is about restoring
OScurrent directory.But you, in the code also use
InitialDirectoryproperty, forcing the dialog every time start from@"c:\";path. Remove this, and it will resolve your problem.