Here's the documentation of TreeView.SelectedNode .
Your ReadFile function works just fine, so the problem has to be in the passed argument (filePath). You could add following lines to the beginning of ReadFile:
if (filePath == null) MessageBox.Show("FilePth has null value");
if (!File.Exists(filePath)) MessageBox.Show("File: '" + filePath + "' not found");
Your "System.NotSupportedException" message could be from a null file name (= no selected node is selected). Also, is treeView2.SelectedNode.ToString() correct or do you try to get treeView2.SelectedNode.FullPath ? In the latter case your TreeView2.PathSeparator should be @"\". Just a few thoughts...
HTH
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
To get the path, you have to use treeView2.SelectedNode.FullPath; property.
And its a bit strange to put all the files one beside another into textBox. At lease seperate them, by using some delimiter like commma:
//selected node:
textBox1.Text = ReadFile(treeView2.SelectedNode.FullPath;
//your method
static string ReadFile(string filePath)
{
string ret = "";
string line;
StreamReader file = new StreamReader(filePath);
while ((line = file.ReadLine()) != null)
ret += line + ", "; //changed to seperate files
return ret;
}
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
:)
You are welcome.
bte, just take it easy... programming is about calmness, concentration and creativness.
bye
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474