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;//获得路径
    }
}

 

posted @ 2022-05-04 14:16  HelloWorld庄先生  阅读(565)  评论(0编辑  收藏  举报