Reputation: 23
I have a text box set up for the user to enter their name. When they enter it in it saves it in the notepad but overwrites the previous name. I want the text file to store all the names not just the most recently entered.
using (StreamWriter objWriter = new StreamWriter(@"..\..\..\Files\playerdetails.txt"))
{
objWriter.Write(txtName.Text);
MessageBox.Show("You are now ready to play");
Form1 myForm1 = new Form1();
myForm1.Show();
}
Upvotes: 0
Views: 50
Reputation: 101731
You can just use File.AppendAllText
method:
File.AppendAllText(@"..\..\..\Files\playerdetails.txt", txtName.Text);
Upvotes: 2