我在WeatherController.cs中使用StreamReader从CSV文件中读取数据。在我的MainWindow中,我使用FileChooseDialog来查找要读取的文件。像这样:
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))
答案 0 :(得分:1)
string folder = Path.GetDirectoryName(file);