Question: I wrote a program which reads a csv file, makes some changes and writes to a new csv file. 

I want the user to be able to select the csv file to be read from their directory using an open file dialog box on a windows form. 

So far I have been able to write some of the code so that the user can look for the file but I am not sure on how to link the file the user has chosen to the steamreader.

This is the code to read and write the csv file

```
try 
{
    using (StreamWriter sw = new StreamWriter("X:/PublishedSoftware/Data/NEWPYAEGON1PENSION.csv"))
    {
        using (StreamReader sr = new StreamReader(""))
        {

```

This is the code for the open file dialog box 

```
private void btnFindAegonFile_Click(object sender, EventArgs e)
{
    openFileDialog1.Filter = "csv files(*.csv)|*.csv|All files(*.*)|*.*";
    openFileDialog1.FileName = "Browse for the AEGON file.";

    DialogResult result = openFileDialog1.ShowDialog();

    txtFindAegonFile.Text = this.openFileDialog1.FileName;

```

Answer: 
I got it working I used:

```
string readfilename = txtFindAegonFile.Text;

try
{
    using (StreamReader sr = new StreamReader(readfilename))
    using (StreamWriter sw = new StreamWriter("X:/PublishedSoftware/Data/NEWPYAEGON1PENSION.csv"))
}

```
Use `openFileDialog1`'s [`FileOK`](http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.fileok%28v=vs.110%29.aspx) event to know when the user has selected a valid file. You can then recive the file path from `openFileDialog1.FileName`.