writing to a text file c# code example
Example 1: c# create a text file
string fileName = @"C:\Temp\Temp.txt";
if (!File.Exists(fileName))
{
using (StreamWriter writer = File.CreateText(fileName))
{
writer.WriteLine("Hello World");
}
}
Example 2: asp.net c# write string to text file
using (StreamWriter writer = new StreamWriter("email.txt", true))
{
writer.WriteLine("your_data");
}
Example 3: write text files with C#
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText);
...
string readText = File.ReadAllText(path);