how to overwrite data in a txt file?

Beef picture Beef · Jun 22, 2011 · Viewed 87.7k times · Source

Possible Duplicate:
Can any one tell why the previous data is still displayed while saving data using StreamWriter

I have WPF C# application, that reads and writes to a .txt file, i know how to write line but line, but how do I overwrite the text that is already the file. This is what I have just to write to the next line of the text file, but I want to over the lines not just write to the next line, thanks.

using (StreamWriter newTask = new StreamWriter("test.txt", true)) 
{
    newTask.WriteLine(name[i].ToString());    
}

Answer

Ryan Gross picture Ryan Gross · Jun 22, 2011

You need to change the second parameter to false:

using (StreamWriter newTask = new StreamWriter("test.txt", false)){ 
        newTask.WriteLine(name[i].ToString());
}