Make a file empty

Posted on April 26, 2008

0


Found someone using Google to figure out how to clear out the contents of a file and hitting my blog. Well, it’s pretty easy – use FileMode.Truncate when opening the file.

using (FileStream fs = File.Open(filepath, FileMode.Truncate, FileAccess.Write)) { // Code to write to the file goes here fs.Close(); }

Advertisement
Posted in: General