Step 1: Form
Drag and down a button and a rich Text box from Tool Box.
Step 2: Code
Double click on "Open File " button and write this code. Before this we have to add 2 namespace.
using System.Data.SqlClient;
using System.Text;
namespace First_Csharp_app
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_click(object sender, EventArgs e)
{
Stream mystream;
OpenFileDialog openfile = new OpenFileDialog ();
if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
if((mystream = openfile .OpenFile() ) ! = null)
string strfilename = openfile .FileName;
String filetext = File.ReadAllText(strfilename);
richTextBox1.text = filetext;
}
}
}
}
Step 3: Code
Run your application and click on "OpenFile" button and select a file.