View Single Post
  #2 (permalink)  
Old December 28th, 2011, 09:09 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi Gary,

Working with files is a bit confusing in .NET because there are so many classes and so many ways you can open them. I think when you're opening the stream, it's writing a new file overwriting the old one if it exists.

I usually use CreateText, AppendText, and OpenText to create, add text at the end of, or read text files. See this example:

Open text file by using CreateText, AppendText, and OpenText in Visual Basic .NET

In your program you probably want to use AppendText so you can add the new text at the end of the existing file.

If you can, you should also try to do the writing inside a For loop instead of using a whole bunch of almost identical Write statements. That would make the code easier to work with and debug.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
Gary108 (December 31st, 2011)