c# - Append input into text file instead of replacing it -


i'm trying take data 2 text boxes, , writing file without replacing current stuff there when button pressed. have far:

private void button1_click_1(object sender, eventargs e)     {         using (streamwriter sw1 = new streamwriter("datanames.txt"))         {             sw1.writeline(textbox1.text);         }          using (streamwriter sw2 = new streamwriter("datanumbers.txt"))         {             sw2.writeline(textbox2.text);         }         } 

right takes input, , replaces whatever in files there 1 line, instead of adding list. help.

use streamwriter constructor (string, boolean) constructor , pass true append.

true append data file; false overwrite file. if specified file not exist, parameter has no effect, , constructor creates new file.

in code pass true like:

using (streamwriter sw1 = new streamwriter("datanames.txt",true)) 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -