C# RestoreDirectory

RestoreDirectory是控制当前程序中的System.Environment.CurrentDirectory的,也就是,当属性设置为true时,System.Environment.CurrentDirectory永远是程序从中启动的文件夹目录;而设置为false是,则每次使用OpenFileDialog选择完文件后,System.Environment.CurrentDirectory会变成最后一次打开文件的目录。

OpenFileDialog与SaveFileDialog都有RestoreDirectory属性。

FolderBrowserDialog 没有RestoreDirectory属性。

C# 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;
}
C# RestoreDirectory
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
    textBoxDir.Text = dialog.SelectedPath;
}

C# RestoreDirectory

上一篇:windows上解决git每次重复输入账号密码


下一篇:Odd-Even Subsequence T17 D57