C#打开一个文件另存为对话框和读取文件对话框
using(System.Windows.Forms.SaveFileDialog saveFile=new System.Windows.Forms.SaveFileDialog()) { saveFile.RestoreDirectory=true; saveFile.Title="文件另存为"; saveFile.Filter="Json文件(*.json)|*json"; saveFile.FileterIndex=0; if(saveFile.ShowDialog()==System.Windows.Forms.DialogResult.OK) { string filrPath=saveFile.FileName;//获得路径 }
}
using(System.Windows.Forms.OpenFileDialog openFile=new System.Windows.Forms.OpenFileDialog ()) { openFile.Multiselect=false;//不能同事选择多个文件夹 openFile.Title="请选择文件"; openFile.Filter="Json文件(*.json)|*json"; if(openFile.ShowDialog()==System.Windows.Forms.DialogResult.OK) { string filrPath=openFile.FileName;//获得路径 } }