Append to text file with TextWriter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am writing some information to a text file using the TextWriter Class.
However I am having problems appending data to a file that already exists and
already has text in it.

I just seem to be overwriting what is in the text file. Can anyone tell me
what I should be doing to append text?

Thanks
Macca
 
Macca said:
I just seem to be overwriting what is in the text file. Can anyone tell me
what I should be doing to append text?

You can you File.Open("filename", FileMode.Append) to get a FileStream
or File.AppendText("filename") to get a StreamWriter to append text.

HTH.

Dan Manges
 
Macca,

You can't be using a TextWriter directly, since it is an abstract class.
You are most likely using a StreamWriter.

How are you initializing it? You should use a FileStream which is
created to append the content to the end of the file, and then pass that to
your StreamWriter.

Hope this helps.
 
Back
Top