How creat and fill data in notpad file?
how can i create notepad file and fill data every time in it when i run my application.?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Oct 8, 2009, 1:03 AM EDT
public static void Main() { string _file = C:\\MyTextFile.txt; if (File.Exists(_file) { AppendToFile(_file ); } else { WriteToFile(_file ); } } static void WriteToFile(string _file ) { StreamWriter SW; SW=File.CreateText(_file ); SW.WriteLine("God is greatest of them all"); SW.WriteLine("This is second line"); SW.Close(); Console.WriteLine("File Created SucacessFully"); } static void AppendToFile(string _file ) { StreamWriter SW; SW=File.AppendText(_file ); SW.WriteLine("This Line Is Appended"); SW.Close(); Console.WriteLine("Text Appended Successfully"); }