首页 > 代码库 > C# 按键保存txt文本

C# 按键保存txt文本

using System.IO;

 

System.Windows.Forms.SaveFileDialog objSave = new System.Windows.Forms.SaveFileDialog();
objSave.Filter = "(*.txt)|*.txt|" + "(*.*)|*.*";

objSave.FileName = "文件" + DateTime.Now.ToString("yyyyMMddHHmm") + ".txt";

if (objSave.ShowDialog() == DialogResult.OK)
  {
         StreamWriter FileWriter = new StreamWriter(objSave.FileName, true); //写文件

          FileWriter.Write(this.txtDetail.Text);//将字符串写入
          FileWriter.Close(); //关闭StreamWriter对象
}

 
 

C# 按键保存txt文本