C# RestoreDirectory属性起什么作用呢?


摘要:
下文讲述c#开发中RestoreDirectory属性的功能说明,如下所示;

RestoreDirectory属性功能:
    用于设置打开和保存文件对话框(OpenFileDialog,SaveFileDialog)所指向的默认路径
    1.当此属性值设置为true时,则指向系统默认目录 
    2.当此属性值设置为false时,则指向我们刚刚打开文件所对应的目录
---此属性值默认值为false

例:

/*
打开文件对话框
*/
string fileName;
OpenFileDialog openFile = new OpenFileDialog();
openFile.InitialDirectory = Application.StartupPath ;
openFile.Filter = "*.txt";
openFile.RestoreDirectory = true;//系统默认目录
openFile.FilterIndex = 1;

if (openFile.ShowDialog() == DialogResult.OK)
{
    fileName= openFile.FileName;
    
}