C# Programming
03-01-2013, 09:15 AM
I have a project that i have to create and write to a text file using the StreamWritter class. i create the file just fine and after playing with it a little got the text to enter into the file correctly but i cant add more text to the file after the inital line or it just truncates whats already inside of it, i want the text inside to add each time the button is clicked even after the program closes and i reopen it. here is my code so far
using System.IO; namespace SWardVideoSalesApplication{ public partial class MainSalesForm : Form { public MainSalesForm() { InitializeComponent(); } #region Variables //TEST VARIABLES StreamWriter testFile = File.CreateText("TestFile2.txt"); #endregion
private void summaryButton_Click(object sender, EventArgs e){ //Displays the summary text file in a label for the user to read //First a simple test of the file writting bool Flag = true; testFile = File. if (Flag) { testFile.WriteLine("This is a test {0}", todayDate.ToString()); testFile.Close(); } else { MessageBox.Show("ERROR"); } }
using System.IO; namespace SWardVideoSalesApplication{ public partial class MainSalesForm : Form { public MainSalesForm() { InitializeComponent(); } #region Variables //TEST VARIABLES StreamWriter testFile = File.CreateText("TestFile2.txt"); #endregion
private void summaryButton_Click(object sender, EventArgs e){ //Displays the summary text file in a label for the user to read //First a simple test of the file writting bool Flag = true; testFile = File. if (Flag) { testFile.WriteLine("This is a test {0}", todayDate.ToString()); testFile.Close(); } else { MessageBox.Show("ERROR"); } }