// 選擇文件: private string SelectPath() { string path = string.Empty; var openFileDialog = new Microsoft.Win32.OpenFileDialog() { Filter = "Files (*.*)|*.*"//如果需要篩選txt文件("Files (*.txt)|*.txt") }; var result = openFileDialog.ShowDialog(); if (result == true) { path = openFileDialog.FileName; } return path } // 選擇路徑 private string SelectPath() { string path = string.Empty; System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = fbd.SelectedPath; } return path; }