C# 选择文件保存路径

public static string SetSaveFilePath(string filterType= "所有文件|*.*",string fileName="我的文件",string defaultExt=".txt")
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = filterType;       //设置文件类型
            dialog.FileName = fileName;                               //设置默认文件名
            dialog.DefaultExt = defaultExt;                              //设置默认格式(可以不设)
            dialog.AddExtension = true;                             //设置自动在文件名中添加扩展名
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                return dialog.FileName;
            }
            return "";
        }

posted @ 2021-09-15 19:13  LuoCore  阅读(1629)  评论(0编辑  收藏  举报