WPF本身并没有相关的类,需要引用winform的命名空间

System.Windows.Forms
获取文件夹路径
System.Windows.Forms.FolderBrowserDialog m_Dialog = new System.Windows.Forms.FolderBrowserDialog();
            System.Windows.Forms.DialogResult result = m_Dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            string m_Dir = m_Dialog.SelectedPath.Trim();
获取指定文件
using Microsoft.Win32;
OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "选择数据源文件";
            openFileDialog.Filter = "txt文件|*.txt|rar文件|*.rar|所有文件|*.*";
            openFileDialog.FileName = string.Empty;
            openFileDialog.FilterIndex = 1;
            openFileDialog.Multiselect = false;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.DefaultExt = "txt";
            if (openFileDialog.ShowDialog() == false)
            {
                return;
            }
            string txtFile = openFileDialog.FileName;

相关文章:

  • 2021-11-28
  • 2021-08-09
  • 2021-12-12
  • 2021-09-15
  • 2021-10-16
  • 2021-12-18
  • 2021-09-08
  • 2021-10-12
猜你喜欢
  • 2021-11-06
  • 2021-12-23
  • 2021-11-20
  • 2021-11-20
  • 2021-12-03
  • 2021-11-06
  • 2021-11-20
  • 2021-11-06
相关资源
相似解决方案