Hello,
I'm using the code below for writing text in a text file.
StreamWriter dosya = new StreamWriter("mac.txt");
dosya.WriteLine("first line");
dosya.WriteLine("second line");
dosya.Close();
But I couldnt be able to find, how can I delete all data in this text file?
Loading

VulpesRank #55 · 29.2K reputationPosted Jun 26, 2011, 11:58 PM EDT
yokzuRank #5,421 · 300 reputationPosted Jun 26, 2011, 11:04 PM EDT
File.Delete("mac.txt");
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jun 26, 2011, 11:05 PM EDT
FileInfo finfo = new FileInfo(@"D:\xyz\filename.txt"); using(TextWriter txtw = new StreamWriter(finfo .Open(FileMode.Truncate))) { txtw .Write("write my new text here"); } hope it works...Morcos Adel115 reputationPosted Jun 26, 2011, 11:31 PM EDT
i think that if you wanna delete all the Data in a text file and not deleting the file
you can do the following:
StreamWriter Sw=new StreamWriter("mac.text");
Sw.AutoFlush=true;
Sw.close();
hope this hepls :)