怎样将textbox(multiline)中的内容保存到文本文件中

robocap 2003-05-22 12:42:03
我想做一个日志,记录鼠标的点击动作或者数据的变动。开始都存放在一个设置为multiline的textbox中,最后程序时,程序自动记录textBox中的内容到一个文本文件中 而且自动按日期给文本文件取名字

麻烦各位大哥大概说说方法 谢谢先~~
...全文
60 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chNET 2003-05-22
  • 打赏
  • 举报
回复

写得很乱但能用:

private void button1_Click(object sender, System.EventArgs e)
{

string st1="";

DateTime dt=DateTime.Now;
string st=dt.Date.ToShortDateString();
string path="c:\\"+st+".txt";

if(File.Exists(path))
{
FileStream fs=File.Open(path,FileMode.Open);

StreamReader sr=new StreamReader(fs);
st1=sr.ReadToEnd();
fs.Close();
sr.Close();
File.Delete(path);
}

FileStream fs1=File.Open(path,FileMode.Create);

StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine (textBox1.Text);
sw.WriteLine ("-----------------------------------");
sw.WriteLine(st1);

sw.Close();
}

:)
adh1978 2003-05-22
  • 打赏
  • 举报
回复
ding
wylcharles 2003-05-22
  • 打赏
  • 举报
回复
Knight94(愚翁)老先生是个强人,我问过他很多问题,不错,兄弟,听他的,肯定对!
帮你顶一个!
dplxp 2003-05-22
  • 打赏
  • 举报
回复
这种内容基本哪本书里都有,为什么不自己先看看那
v192 2003-05-22
  • 打赏
  • 举报
回复
怎么现在都是不看书,就开始先干着再说?晕阿
Knight94 2003-05-22
  • 打赏
  • 举报
回复
Sorry:

StreamWriter myTxtWriter=new StreamWriter(
DateTime.Now.Date.ToString("yyyyMMdd")+".txt",false);
Knight94 2003-05-22
  • 打赏
  • 举报
回复
using System.IO;

StreamWriter myTxtWriter=new StreamWriter(
DateTime.Now.Date.ToString()+".txt",false);
myTxtWriter.Write(textBox1.Text);
myTxtWriter.Flush();
myTxtWriter.Close();

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧