Some Creativity

Weblog of Siddharth Uppal

Make a file empty

leave a comment »

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();
            }

Written by Sid

April 26, 2008 at 9:25 am

Posted in General

Leave a Reply