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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleRemove 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
More Pages to Explore .....