The only valid way to change anything in a text file is be reading it at least once. Why? Because lines are defined by the positions of end-of-line characters, so the lines have different length. Before you read all lines, you don't know the position of N-the line in the file.
For simple files, you can read it all in memory, and then write it all back, after your modifications. You can use
File.ReadAllLines
:
http://msdn.microsoft.com/en-us/library/system.io.file.readalllines.aspx[
^].
—SA