如何使用OpenFileDialog快速打开应用程序的文件夹?
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
...........
}
答案 0 :(得分:2)
如果您希望覆盖其值设置的默认方式之一(在MSDN上描述),请使用FileDialog.InitialDirectory Property。
openFileDialog1.InitialDirectory = @"C:\"; // based on comment of question
答案 1 :(得分:2)
猜测你的意思是“在应用程序的文件夹中显示OpenFileDialog”,只需将OpenFileDialog.InitialDir
设置为应用程序的文件夹,然后再显示OpenFileDialog
。
string AppPath = Path.GetDirectoryName(Application.ExecutablePath);;
openFileDialog1.InitialDir = AppPath;
如果您在查找应用程序目录时需要帮助,请参阅Getting root folder of application