Create a Text File and Write in it in Window Application

Step 1: Form

Drag and down a Button from tool box and give name it as Create File.



Step 2: Before creating a Text File.

Right click on Solution Explorer and click on "Open Folder in Window Explorer" Go to this path.

"WindowFormApplication2 -> Bin -> Debug"
 


Here you will see that there is not any Text File.

Step 3: Code
 


Double click on Button and write this code.
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

using System.Text;

using System.IO;

using System.Text;

 

namespace First_Csharp_app

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Button1_click(object sender, EventArgs e)

        {

            StreamWriter File = new StreamWriter("Text_File.Text");

            File.Write("Hi Munesh, How r u");

            File.Write("Hi Munesh, How r u");

            File.Write("Hi Munesh, How r u");

        }

    }

}

Step 4: After creating a Text File.

Now run your application and then you will go on that path you will see that file.



Step 5: Run application

Run your application and open that Text File.
 


you can go on my Blog_munesh
Ebook Download
View all
Learn
View all