In this article, we will learn, how we can write Text file using C#, To write in file we have two class File and FileInfo which help us to write text in a file.

The ‘File’ class holds static methods and offers security checks on all the methods. The FileInfo holds instance methods and security check is not needed. For writing in a text file, we have abstract classes like the TextWriter class.

public void Write()
{
   //path of file
   var path = @"E:\TheCodeHubs.txt";

   using (StreamWriter sw = new StreamWriter(path))
   {
     sw.Write("Write In Text File In ASP.NET MVC");
   }
}

If you are looking for a reading a file in c#, you can read from here.