选择文件,将路径显示在名为txbx的textbox上
// 在WPF中, OpenFileDialog位于Microsoft.Win32名称空间 Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog(); //dialog.Filter = "文本文件|*.txt"; if (dialog.ShowDialog() == true) { this.txbx.Text = dialog.FileName; }
弹出资源管理器:
System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory);
//浏览 private void Border_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e) { //打开文件 var path = ""; Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog(); dialog.Multiselect = true; if (dialog.ShowDialog() == true) { path = dialog.FileName; } else { MessageBox.Show("未选择文件"); } //获取文件路径与名称与后缀 this.txtbox1.Text = path; }
保存文件到本地:
private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.Filter = "xlsx|*.xlsx|xlsx表格|*.xls"; if (sfd.ShowDialog() == true) { /* * 保存方法 */ MessageBox.Show("保存成功"); } }
直接用程序打开文件
if (System.Windows.Forms.MessageBox.Show("导出成功,是否打开文件?", "提示", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { //封装我们要打开的文件 但是并不去打开这个文件 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(paths); //创建进程对象 System.Diagnostics.Process pro = new System.Diagnostics.Process(); //告诉进程要打开的文件信息 pro.StartInfo = psi; //调用函数打开 pro.Start(); }
//或
new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo(newPath_qcccl) }.Start();