Just some information
I suppose you were not using System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
before you found a solution.
Without an absolute path, for example: var sectReader = new StreamReader("section.csv");
Dotnet framework will look up the file in the current working directory, which isn’t guaranteed to be Libraries
folder.
If the file is not there, a FileNotFoundException
will be raised. Since the constructor isn’t enclosed in a try...catch
clause, the entire method will abort and _sectionform.Show
never gets executed.
From a programming paradigm perspective, I’d recommend you use try...catch
to show a message instead of silent fail, e.g.:
public void DisplayForm1()
{
string path = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
StreamReader sectReader = null;
try
{
sectReader = new StreamReader(path+@"\Grasshopper\Libraries\section.csv");
} catch (FileNotFoundException e) {
MessageBox.Show("CSV file not found");
return;
}
_sectionform = new Utilities.sectionform();
_sectionform.FormClosed += OnFormClosed;
GH_WindowsFormUtil.CenterFormOnCursor(_sectionform, true);
_sectionform.Show(Grasshopper.Instances.DocumentEditor);
}
PS: Remember to Dispose
the StreamReader
or use using(...)
clause to prevent potential resource leak. example