writing to text file c# code example
Example 1: asp.net c# write string to text file
using (StreamWriter writer = new StreamWriter("email.txt", true))
{
writer.WriteLine("your_data");
}
Example 2: write text files with C#
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText);
...
string readText = File.ReadAllText(path);
Example 3: c# how to write to a file
using System.IO;
using System.Threading.Tasks;
class WriteAllLines
{
public static async Task ExampleAsync()
{
string[] lines =
{
"First line", "Second line", "Third line"
};
await File.WriteAllLinesAsync("WriteLines.txt", lines);
}
}