调出windows对话框新建文件
使用System.Windows.Forms.SaveFileDialog或者Microsoft.Win32.SaveFileDialog
System.Windows.Forms.SaveFileDialog saveFile = new System.Windows.Forms.SaveFileDialog(); saveFile.Title = "新建文件"; saveFile.FileName = ""; saveFile.Filter = "*.txt"; //新建文件类型为txt string filename = string.Empty; if (saveFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Save document System.IO.FileStream fs = (System.IO.FileStream)saveFile.OpenFile();//输出文件 } else { return; }
打开文件
使用System.Windows.Forms.OpenFileDialog 或者Microsoft.Win32.OpenFileDialog
System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog(); openFile.Title = "打开文件"; openFile.Filter = _filePathParameter.fileFilter(); if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TextValue = openFile.FileName; //获取文件位置+文件名 }