how to write data to a text file in 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: save text input into a txt file in c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter txt = new StreamWriter("C:\\demo\\demo.txt");
txt.Write(textBox1.Text);
txt.Close();
}
}
}