C# RestoreDirectory
RestoreDirectory是控制当前程序中的System.Environment.CurrentDirectory的,也就是,当属性设置为true时,System.Environment.CurrentDirectory永远是程序从中启动的文件夹目录;而设置为false是,则每次使用OpenFileDialog选择完文件后,System.Environment.CurrentDirectory会变成最后一次打开文件的目录。
OpenFileDialog与SaveFileDialog都有RestoreDirectory属性。
FolderBrowserDialog 没有RestoreDirectory属性。
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; }
posted on 2019-10-16 18:02 Keepshining 阅读(871) 评论(0) 编辑 收藏 举报