Tuesday, May 13, 2014

Text File Reader Application using C#.NET Windows Form Application.

Open Visual Studio and create a new project.
Give a design to a form like this :-

Now in the Code file add namespace :-

                             Using System.IO;

Double click on Open button :-


private void button1_Click(object sender, EventArgs e)
        {
            if (File.Exists(textBox1.Text) == true)
            {
                StreamReader sr = new StreamReader(textBox1.Text);
                richTextBox1.Text = sr.ReadToEnd();
                sr.Close();
            }
            else
            {
                MessageBox.Show("This file is not exist");
            }
        }

Double click on Clear button :-


private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

Save it, Execute it and enjoy it :P :)

No comments:

Post a Comment