2014-05-01 89 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(文件);