1 SaveFileDialog saveFileDialog = new SaveFileDialog(); 2 //初始化路径 3 saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 4 saveFileDialog.Filter = "Microsoft Excel(*.xls)|*.XLS"; 5 //若文件已存在,是否覆盖 6 saveFileDialog.OverwritePrompt = true; 7 8 saveFileDialog.FileName = fileName; 9 10 if ((saveFileDialog.ShowDialog()) == DialogResult.OK) 11 { 12 fileNamePath = saveFileDialog.FileName.ToString(); 13 } 14 else 15 { 16 return; 17 }
参考:https://www.cnblogs.com/tommy-huang/p/4506597.html(C#(Winform)的SaveFileDialog(文件保存对话框)控件使用)