Assuming the btnAddSave_Click is triggered by a click (as its name implies):
- you don't need while, just add to file.
- to ADD to file instead of having it OVERWRITTEN you need
StreamWriter writer = new StreamWriter(outFile, True)
if you don't have second parameter, the file will be overwritten with the last values.
- consider using directive (
using writer = new StreamWriter...{}
) for automatic closure and disposal. The code above has memory leak bug - if there is an exception in writing to file StreamWriter and File will not be closed.
Wrap entire thing into Try...Finally and close / dispose in finally block. Better solution is to simply use "using" keyword.