Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Help! Need to write to end of file

Oct 30, 2010 8:57AM PDT

Hello
I'm using StreamWriter to write data to a file. However every time it writes new data, it overwrites what's already there. Can someone help me make it so that it writes on the next line after what's already there? Go to end of file?

I'm very new to scripting.

Thanks

Discussion is locked

- Collapse -
Always keep the documentation handy...
Oct 30, 2010 9:57AM PDT

For instance, the StreamWriter documentation shows that there are overloaded constructors that let you specify whether the content should be appended to the file or overwrite it. As you spend time developing in a language you will memorize most of the common functionality, but even the most experienced developers keep the documentation handy. Keep that in mind and you can do just about anything you put your mind to.

Hope this helps,
John

- Collapse -
Thanks
Oct 31, 2010 8:59AM PDT

Hello, thank you so much, your reply fixed it for me Happy

- Collapse -
Reposted for jonewatson
Nov 1, 2010 6:18PM PDT

But I left out the ad-link to a programming company.

Kees
--------------------

I think this cause may be the overloaded constructor that let you specify whether the content should be appended to the file or overwrite it.
The first step to creating a new text file is the instantiation of a StreamWriter object. The most basic constructor for StreamWriter accepts a single parameter containing the path of the file to work with. If the file does not exist, it will be created. If it does exist, the old file will be overwritten.