Ok. I'm having an issue with the following bit of code:
StreamReader arrComputer = new StreamReader(FileDialog.FileName);
My first question had been answered already now my second question focuses on the tail end of this code.
I'm reading a text file StreamReader
that the user selects with a button event using OpenFileDialog
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.InitialDirectory = @"C:\";
fileDialog.Filter = "Text|*.txt|All|*.*";
if (fileDialog.ShowDialog() == DialogResult.OK) ;
textBox1.Text = fileDialog.FileName;
buttonRun.Enabled = true;
}
The later in the code the user will click a "Run" button to exectue some code against each item in the list.
I'm having problems using StreamReader to parse the list using the following code:
private void buttonRun_Click(object sender, EventArgs e)
{
StreamReader arrComputer = new StreamReader(FileDialog.FileName);
}
This is the error I receive:
An object reference is required for the non-static field, method, or property 'System.Windows.Forms.FileDialog.FileName.get'
I think I understand the problem but I'm having a hard time working it out.