How to add text files into a textbox, Richtextbox, label in c#
First, add one textbox and a button from the toolbox and then add the yellow highlighted code as following.
using System.IO;
public Form1()
{
InitializeComponent();
}
Now go to the button1 click event and copy the yellow highlighted code as follows.
private void button1_Click(object sender, Event Args e)
{
Stream myStream;
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if ((myStream = openFileDialog.OpenFile()) != null)
{
string strfilename = openFileDialog.FileName;
string filetext = File.ReadAllText(strfilename);
label1.Text = filetext;
}
}
}
No comments:
Post a Comment