shilvyan  
View Code
 1 /// <summary>
 2         /// 保存文档
 3         /// </summary>
 4         /// <param name="txt"></param>
 5         /// <param name="filename"></param>
 6         public void Save(string txt, string filename)
 7         {
 8             if (txt != string.Empty)
 9             {
10                 System.Windows.Forms.SaveFileDialog saveFile = new System.Windows.Forms.SaveFileDialog();
11                 saveFile.Filter = "文本文件(*.txt)|*.txt";
12                 saveFile.DefaultExt = "txt";
13                 saveFile.FileName = filename;
14                 if (saveFile.ShowDialog(this) == DialogResult.OK)
15                 {
16                     string saveFilePath = saveFile.FileName;//定义保存的文件路径
17                     using (StreamWriter sw = File.CreateText(saveFilePath))
18                     {
19                         sw.Write(txt);
20                         sw.Close();
21 
22                     }
23                 }
24             }
25         }

 

posted on 2013-05-10 10:21  shilvyan  阅读(248)  评论(0编辑  收藏  举报