1
Reply

Can't read a text file

Meriadoc Lawes

Meriadoc Lawes

Dec 2 2009 2:44 PM
2.8k
i'm trying to read the text in a text file. This is my code: namespace ReadFileTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly(); private void button1_Click(object sender, EventArgs e) { System.IO.StreamReader myFile = new System.IO.StreamReader(ass.GetManifestResourceStream(@"ReadFileTest.TextFile1.txt")); while (myFile.Peek() != -1) { myFile.ReadLine(); } string myString = myFile.ReadToEnd(); myFile.Close(); textBox1.Text = myString; } } }

Answers (1)