C# RestoreDirectory

OpenFileDialog与SaveFileDialog都有RestoreDirectory属性,这个属性默认是false,打开一

个文件后,那么系统默认目录就会指向刚才打开的文件。如果设为true就会使用系统默认目录

string fName;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Application.StartupPath ;
openFileDialog.Filter = "sql文件|*.sql|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
    fName = openFileDialog.FileName;
    textBoxScript.Text = fName;
}
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
    textBoxDir.Text = dialog.SelectedPath;
}
FolderBrowserDialog 没有该属性
posted @ 2018-05-09 11:27  zhaogaojian  阅读(1735)  评论(0编辑  收藏  举报