[C#] Write Text File

This function creates a text file when it runs. In the directory where you give in filePath and strContent you want to write. If you view the contents of this file, you'll see the following textual representation of the date and time when the program last ran.

void WriteTextFile(string filePath, string strContent)
{
    StreamWriter sW = new StreamWriter(filePath);
    sW.Write(strContent);           // Not line breaks
    //sW.WriteLine(strContent);     // Write and line breaks
    sW.Write(DateTime.Now);         // Write Date

    // Flush and Close
    sW.Close();
}

Your Reply