直接上代碼 1 public TestOne() 2 { 3 InitializeComponent(); 4 SaveFileDialog();//調用打開SaveFileDialog 保存對話框 5 } 6 7 #region 保存對話框 8 private void SaveFileDialo
直接上代碼
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 }