WPF文件和文件夹的操作
时间:2022-03-18 01:47
1、对文件的操作
private void button_chose_Click(object sender, RoutedEventArgs e) { var openFileDialog = new Microsoft.Win32.OpenFileDialog() { Filter = "Excel Files (*.sql)|*.sql" }; 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; }
本类排行
- 1terminate called after throwing an instance of 'std::cad_alloc' what():std::bad_alloc
- 2动态 WebApi 引擎使用教程(3行代码完成动态 WebApi 构建)
- 3windows 查看文件的md5/sha1/sha256
- 4打造一个window桌面应用:在线聊天对话机器人
- 5git windows下换行符问题 LF与CRLF转换
- 6[Linux]Windows远程CENTOS7桌面
- 7FileExistsError: [WinError 183] 当文件已存在时,无法创建该文件。
- 8K8S--可视化界面Kubernetes Dashboard(API Server方式)
- 9搜索引擎sphinx的windows安装和使用
- 10Redis安装成windows服务