2014-05-01 57 views
2

我在WeatherController.cs中使用StreamReader从CSV文件读取数据。在我的MainWindow中,我使用FileChooseDialog来查找要读取的文件。像这样:使用FileChooserDialog解析文件路径GtkSharp

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(); 
} 

如何从我的WeatherController.cs StreamReader中使用此文件获取文件路径? 我的StreamReader:

using (StreamReader sr = new StreamReader (file)) 

回答

1

串夹= Path.GetDirectoryName(文件);