Quantcast
Channel: Remove all previous text before writing - Stack Overflow
Browsing all 7 articles
Browse latest View live

Answer by MicheevSemen for Remove all previous text before writing

Simply change the second parameter from true to false in the contructor of StreamWriter.using (StreamWriter sw = new StreamWriter(("Default//DefaultProfile.txt").ToString(), **false**))See StreamWriter...

View Article



Answer by Amit Jaura for Remove all previous text before writing

You can use FileMode.Truncate. Code will look likeFileStream fs = new FileStream(filePath, FileMode.Truncate, FileAccess.Write ){ fs.Close();}

View Article

Answer by BrianK for Remove all previous text before writing

The most straightforward and efficient technique is to use the StreamWriter constructor's boolean parameter. When it's set to false it overwrites the file with the current operation. For instance, I...

View Article

Answer by MethodMan for Remove all previous text before writing

You can look at the Truncate methodFileInfo fi = new FileInfo(@"Default\DefaultProfile.txt");using(TextWriter txtWriter = new StreamWriter(fi.Open(FileMode.Truncate))){ txtWriter.Write("Write your line...

View Article

Answer by Sam Axe for Remove all previous text before writing

System.IO.File.Delete, or one of the System.IO.FileStream constructor overloads specifying FileMode.Create

View Article


Answer by Cᴏʀʏ for Remove all previous text before writing

You could just write an empty string to the existing file:File.WriteAllText(@"Default\DefaultProfile.txt", string.Empty);Or change the second parameter in the StreamWriter constructor to false to...

View Article

Remove all previous text before writing

I am writing a text file and each time i write i want to clear the text file. try{ string fileName = "Profile//"+ comboboxSelectProfile.SelectedItem.ToString() +".txt"; using (StreamWriter sw = new...

View Article
Browsing all 7 articles
Browse latest View live




Latest Images