C#:開啟 檔案/資料夾選擇框,選取,並獲得路徑名稱
阿新 • • 發佈:2018-12-27
using System; using System.Windows.Forms; //選取檔案,並獲得路徑 private void button1_Click(object sender, EventArgs e) { var f = new OpenFileDialog(); //f.Multiselect = true; //多選 if (f.ShowDialog() == DialogResult.OK) { String filepath = f.FileName;//G:\新建資料夾\新建文字文件.txt String filename = f.SafeFileName;//新建文字文件.txt this.textBox1.Text = filename +" "+filepath; } } //選取資料夾,並獲得路徑 private void button2_Click(object sender, EventArgs e) { FolderBrowserDialog f = new FolderBrowserDialog(); if (f.ShowDialog() == DialogResult.OK) { String DirPath = f.SelectedPath; this.textBox1.Text = DirPath;//G:\新建資料夾 } }