从textbox追加文本到文本文件
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
System.IO.StreamWriter savemessage = new System.IO.StreamWriter( "*.txt(路径) ");
try
{
savemessage.WriteLine(TextBox1.Text);
savemessage.WriteLine(Label1.Text);
}
catch
{
throw;
}
finally
{
savemessage.Close();
}
}
这个方法只会将从textbox存到.txt文件,但会覆盖上次内容...
怎样才能添加进.txt而保存上次的内容...
顺便问下,怎么读出来,在另一个readonly的textbox里显示.txt文件的所有内容?
------解决方案--------------------System.IO.StreamWriter savemessage =
new System.IO.StreamWriter( "*.txt(路径) ", true, Encoding.Default);
try
{
savemessage.WriteLine(textBox1.Text);
savemessage.WriteLine(label1.Text);
}
catch
{
throw;
}
finally
{
savemessage.Close();
}
------解决方案--------------------顺便问下,怎么读出来,在另一个readonly的textbox里显示.txt文件的所有内容?
-----------------------------
System.IO.StreamReader readmessage = new System.IO.StreamReader( "e:\\test.txt ", Encoding.Default);
try
{
textBox1.Text = readmessage.ReadToEnd();
}
catch
{
throw;
}
finally
{
readmessage.Close();
}