OpenFileDialog in C#

Introduction

OpenFileDialog is a class  which is used for the open the file from computer in RichTextBox.

Use of OpenFileDialog step by step

Step 1. First of all we will take a button and RichTextBox from toolbox on the windows form.

filedialog1.gif

Step 2. Now we will take OpenFileDialog from toolbox on Windows form.

filedialog2.gif

Step 3.Now we we will coding on button click.

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;
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
       {
            openFileDialog1.ShowDialog();
            richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
        }
    }
}

Step 4. Run application (press F5) then click the button.

filedialog3.gif

Step 5. Open the file.

fildialog4.gif