直接上代码
1 public TestOne() 2 { 3 InitializeComponent(); 4 SaveFileDialog();//调用打开SaveFileDialog 保存对话框 5 } 6 7 #region 保存对话框 8 private void SaveFileDialog() 9 { 10 //string localFilePath, fileNameExt, newFileName, FilePath; 11 SaveFileDialog saveFileDialog1 = new SaveFileDialog(); 12 13 //设置文件类型 14 saveFileDialog1.Filter = " txt files(*.txt)|*.txt|All files(*.*)|*.*"; 15 16 //设置默认文件类型显示顺序 17 saveFileDialog1.FilterIndex = 2; 18 19 //保存对话框是否记忆上次打开的目录 20 saveFileDialog1.RestoreDirectory = true; 21 22 //点了保存按钮进入 23 if (saveFileDialog1.ShowDialog() == DialogResult.OK) 24 { 25 //获得文件路径 26 //localFilePath = saveFileDialog1.FileName.ToString(); 27 28 //获取文件名,不带路径 29 //fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\") + 1); 30 31 //获取文件路径,不带文件名 32 //FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\")); 33 34 //给文件名前加上时间 35 //newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt; 36 37 //在文件名里加字符 38 //saveFileDialog1.FileName.Insert(1,"dameng"); 39 40 System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();//输出文件 41 42 //fs输出带文字或图片的文件,就看需求了 43 } 44 }