I am trying to develop a user interface, where users can input their name, id and hometown and I am saving it into a text file.
File.WriteAllText(path,"name"+" " + textBox2.Text+ Environment.NewLine +
"number"+" "+ textBox3.Text+Environment.NewLine + "town"+" " +
textBox4.Text+Environment.NewLine );
This works but the data of the users is written in the text boxes and it works only for the first user, when I enter new data and click the button with the function, it overwrites the first user's data and that way I am not able to save more than 1 user's data.
Please suggest the required modification in the code.
File.WriteAllText
will always overwrite the current file if it exists. Use File.AppendAllText
instead.