string defaultfilePath = ""; private void btn_OpenFile_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = false; dialog.Description = "請選擇文件路徑"; if (defaultfilePath != "") { //設置這次默認目錄爲上一次選中目錄 dialog.SelectedPath = defaultfilePath; } DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { string foldPath = dialog.SelectedPath; txt_Directory.Text = defaultfilePath = foldPath; string[] files = Directory.GetFiles(txt_Directory.Text + @"\", "*.xls"); foreach (string file in files) { MessageBox.Show(file); } } }