We write some data in textbox and it will be save in a text file in the given path.
Initial chamber
Step 1: Open Visual Studio 2010, Go to File, New, Projects, then under Visual C# select Windows.

You can change the name of the project and browse your project to different location too. And then press – OK.
Now go to any drive, make a folder demo and save a demo.txt file.

Design chamber
Step 2: Now open your Form1.cs file, where we create our design for inserting data into Text File. We will drag one Textbox and a button to Form1.cs. You will see your Form look like this.
Form1.cs [design]:

Change the property of textbox - Multiline as True.
Code chamber
Right click on the blank part of Form1.cs and View Code. You will see you are entered in the code part of the form. Write the following code and then Press F5 to run the project.
Form1.cs:
- 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();
- }
- }
- }
Save to text file


Maitrey PandyaPosted Apr 23, 2020, 5:13 PM
What if I want user to decide the file name and location? What should be my this line? TextWriter txt = new StreamWriter("C:\\demo\\demo.txt");
Jawad BenaouichPosted Feb 12, 2020, 8:24 AM
HOW I CAN SAVE ALL TIME AND STAY THE OLD INFORMATION ,n THANK U
Siti ZiPosted Aug 20, 2018, 9:10 PM
Public void ReadGeneralConfig() { StreamReader generalconfigfile = new StreamReader(@"generalconfig.txt"); string line; while ((line = generalconfigfile.ReadLine()) != null) { if (line.Contains("local")) { localIP = line.Substring(line.IndexOf("=") + 1); } if (line.Contains("gatelane")) { gatelane_ = line.Substring(line.IndexOf("=") + 1); } } generalconfigfile.Close(); }
Siti ZiPosted Aug 20, 2018, 9:10 PM
Here is my code for my question,
Siti ZiPosted Aug 20, 2018, 9:08 PM
I have text file with datas and I want it to be like automatically inserted into the representative textboxes once I start to run the program in windows application from in C#?
Dharmendra Kumar PanditPosted Jun 11, 2018, 5:19 AM
Nice One. Full working.
amit tiwariPosted Jun 3, 2017, 1:54 AM
How i can save the text with everytime with a current date in the demo file
Sonu ChaudharyPosted Mar 17, 2016, 7:36 AM
good one
Arul RPosted Oct 28, 2015, 5:27 AM
Good one !!!
Arul RPosted Oct 28, 2015, 5:26 AM
Good one !!!
Santhakumar MunuswamyPosted Oct 25, 2015, 11:34 AM
Good one