Hello, when I use streamwriter, it writes the data, then puts the cursor to the top of the document, it tends to overwrite it I think? How do I make it go at the bottom so it prints the next lot below it?
StreamWriter.EndOfStream(); doesn't work
Printable View
Hello, when I use streamwriter, it writes the data, then puts the cursor to the top of the document, it tends to overwrite it I think? How do I make it go at the bottom so it prints the next lot below it?
StreamWriter.EndOfStream(); doesn't work
you are being very vague, and what you are saying is not true. You probably need to post some code, so that we can see where you are going wrong.
Sorry, I am ignorant. I just started C# the other day.
Does that help at all?Code:static void Header1(_cnf cnf, string var1, string var2, string var3, StreamWriter logF)
{
logF.WriteLine("------------------------------------------");
logF.WriteLine("Text: "+ var1);
logF.WriteLine("Text: "+ var2);
logF.WriteLine("Text: "+ var3);
// Need to go to the end of the file.
logF.Flush();
}
- Tom
Helps a little. Actually you should probably look at the overloaded methods for creating your stream writer. There is an overload with a boolean parameter for appending to the file instead of overwriting.
Code:System.IO.StreamWriter aa = new System.IO.StreamWriter("myfile.txt", true);
It still does not help me, or the previous poster. We need to see more code flow, if you are opening and closing the stream everytime you want to write, then you need to use the append flag. If you open the stream once and write everything, there is something else wrong.
sotoasty's post solved it for me, thanks :)
thanks guys :)
@sotoasty ; Thank you very much bro, i didn't even know there is an overload with a Boolean :), that [,true] parameter, made everything True, Thanks again.
Glad this old post helped, but no need to guess what is available or rely on a 3 year old thread. Instead take a look at what is available for the class you are interested in in Msdn.
http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
The msdn documentation will show you the different constructors, properties and methods for a class. Often it will also show you sample code as well.