I am trying to browse for .doc, .text, etc file and paste location to textbox3.text. I am getting underlines and I don't know what I missed.
here is code:
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog bDialog = new OpenFileDialog();
bDialog.Title = "Open Word or Text File";
bDialog.Filter = "Text Files|*.doc;*.docx;*.txt;*.text";
bDialog.InitialDirectory = @"C:\";
if (bDialog.ShowDialog() == DialogResult.OK)
{
File2Lines = System.IO.File.ReadAllLines(bDialog.FileName.ToString());
}
textBox3.Text = File2Lines;
}
and image with underlines: http://shrani.si/f/3J/bu/2ALFViEN/missing.png
Any solution? (if something doesn't make any sense it's because I am noob)
You haven't declared File2Lines
as a variable. Also, ReadAllLines
returns a String[]
and not a string
. Try:
string[] File2Lines = System.IO.File.ReadAllLines(bDialog.FileName.ToString());
then
textBox3.Lines = File2Lines;