Open Text files in C#
1-Add one Button & RichTextBox from toolbox
Now add the yellow highlighted namespace as follows.
using System.IO;
Now add the yellow highlighted namespace as follows.
using System.IO;
namespace WindowsFormsApp1
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
Now go to the button1_click event and copy the yellow highlighted code. private void button1_Click(object sender, EventArgs e)
{
Stream stm;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if ((stm = ofd.OpenFile()) != null)
{
string str = ofd.FileName;
string ftxt = File.ReadAllText(str);
textbox1.Text = ftxt;
}
}
}
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
Now go to the button1_click event and copy the yellow highlighted code. private void button1_Click(object sender, EventArgs e)
{
Stream stm;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if ((stm = ofd.OpenFile()) != null)
{
string str = ofd.FileName;
string ftxt = File.ReadAllText(str);
textbox1.Text = ftxt;
}
}
}
No comments:
Post a Comment