- 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:\新建文件夹
- }
参考:
C#:打开 文件/文件夹选择框,选取,并获得路径名称_c#带有输入框的选取文件按钮,输入框中显示选取文件的路径-CSDN博客