Writing and Reading Text File using C#
Introduction Reading and Writing to text file is common requirement of programmers. C# provides a convenient way to work with text files. .NET Framework includes convenience classes that make reading and writing text files very easy. Actually, to write (create) or read files, there is three certain steps we need to follow. (i) Opening the file (ii) Read or Write (create new file) file (iii) Close the file The best way to understand working with files is to jump right into the code, let's jump. Writing File using System; using System.IO; class WritingFile { static void Main( string [] args) { //opening a file stream to write text TextWriter tW = new StreamWriter ( "page.txt" ); //write the line to file tW.WriteLine( "text goes here" ); //close the stream tW.Close(); } } In above code, 'System' namespace is base or say primary