選擇文件,將路徑顯示在名為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();