Every time I click on a file, I get the error 

> 
> Empty path name is not legal
> 
> 
> 

I need a user to upload a `.txt` or `.csv` file and have the contents of that file to display in the data grid view. Everything works fine except for this one error that occurs on this line: 

```
var sr = new StreamReader(openFileDialog1.FileName);

```

Full code.

```
private void selectButton_Click (object sender, EventArgs e)
{
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        try
        {
            var sr = new StreamReader(openFileDialog1.FileName);
            SetText(sr.ReadToEnd());
        }
        catch (SecurityException ex)
        {
            MessageBox.Show($"Security error.\n\nError message{ex.Message}\n\n" +
                $"Details:\n\n{ex.StackTrace}");
        }
    }
}

```