1、对文件的操作
private void button_chose_Click(object sender, RoutedEventArgs e) { var openFileDialog = new Microsoft.Win32.OpenFileDialog() {
DefaultExt =".sql", Filter = "Excel Files (*.sql)|*.sql|All files(*.*)|*.*" }; var result = openFileDialog.ShowDialog(); if (result == true) { this.textblock_filename.Text = openFileDialog.FileName; } }
2、文件夹的操作,选择文件夹对话框:WPF中似乎没有打开文件夹对话框,不过可以通过winform的方法打开,调研之前需要引用System.Windows.Forms;
private void button_runScript_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog m_Dialog = new FolderBrowserDialog(); DialogResult result = m_Dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.Cancel) { return; } string m_Dir = m_Dialog.SelectedPath.Trim(); this.textblock_filename.Text = m_Dir; }