Question

I am using a StreamReader in WeatherController.cs to read data form a CSV file. And in my MainWindow i am using a FileChooseDialog to find the file to read from. Like so:

protected void OnButton2Clicked (object sender, EventArgs e)
{
    //Open file dialog and choose a file.
    Gtk.FileChooserDialog fc=
        new Gtk.FileChooserDialog("Choose the file to open",
            this, 
            Gtk.FileChooserAction.Open,
            "Cancel",Gtk.ResponseType.Cancel,
            "Open",Gtk.ResponseType.Accept);
    fc.Filter = new FileFilter ();
    fc.Filter.AddPattern ("*.csv");

    if (fc.Run() == (int)Gtk.ResponseType.Accept) 
    {
        b_Next.Sensitive = true;
        System.IO.FileStream file = System.IO.File.OpenRead(fc.Filename);
        file.Close();

    }
    //Destroy() to close the File Dialog
    fc.Destroy();
}

How do i get the file path from this file to be used in my WeatherController.cs StreamReader? My StreamReader:

using (StreamReader sr = new StreamReader (file))
Was it helpful?

Solution

string folder = Path.GetDirectoryName( file );

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top