Вот решил вот так вот свой вопрос.
private void button1_Click(object sender, EventArgs e)
{
OpenFilesToTreeView(@"d:\123.txt", treeView1);
}
Функция открытия файла
public void OpenFilesToTreeView (string NameFiles, TreeView treeview)
{
string lineFile;
string[] tmplineFile;
FileStream file1 = new FileStream(NameFiles, FileMode.Open);
using (StreamReader readerFiles = new StreamReader(file1))
{
while ((lineFile = readerFiles.ReadLine()) != null)
{
tmplineFile = new[] { lineFile };
BuildTree(treeview.Nodes, tmplineFile);
}
}
}
Функция заполнения TreeView
private void BuildTree(TreeNodeCollection nodes, string[] list)
{
foreach (var path in list)
{
var childs = nodes;
var pathAndFile = path.Split(';')[0];
var parts = pathAndFile.Split('\\');
for (int i = 0; i < parts.Length - 1; i++)
{
childs = FindOrCreateNode(childs, parts[i]).Nodes;
}
}
}
private TreeNode FindOrCreateNode(TreeNodeCollection coll, string name)
{
var found = coll.Find(name.ToLower(), false);
if (found.Length > 0) return found[0];
return coll.Add(name.ToLower(), name);
}
Функция заполнения ListView по клику дерева
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
listView1.Items.Clear();
string lineFile;
string[] tmplineFile;
string tmpPath;
string[] tmpFiles;
string FullPathTree = e.Node.FullPath.ToString() + "";
//string tmpFullPath = e.Node.FullPath.ToString() + "";
FileStream file1 = new FileStream(@"d:\123.txt", FileMode.Open);
using (StreamReader readerFiles = new StreamReader(file1))
{
while ((lineFile = readerFiles.ReadLine()) != null)
{
tmplineFile = new[] { lineFile };
foreach (string path in tmplineFile)
{
tmpPath = path.Split(';')[0];
if (FullPathTree.TrimEnd() == tmpPath.ToString().TrimEnd())
{
tmpFiles = path.Split(';');
string[] col = { tmpFiles[1], tmpFiles[2], tmpFiles[3], tmpFiles[4]};
var listview = new ListViewItem(col);
listView1.Items.Add(listview);
}
}
}
}
}
Ну и формат текстового файла
c:\Windows\System32\;test.dll;Size;Date;CheckSumm
c:\Windows\System32\;test1.dll;Size;Date;CheckSumm
c:\Windows\System32\;test2.dll;Size;Date;CheckSumm
c:\Windows\System\;test1.dll;Size;Date;CheckSumm
c:\Windows\System\;test2.dll;Size;Date;CheckSumm
c:\Windows\System\;test3.dll;Size;Date;CheckSumm
c:\Windows\System\;test4.dll;Size;Date;CheckSumm
c:\Windows\Temp\;wtest1.dll;Size;Date;CheckSumm
c:\Windows\Temp\;wtest2.dll;Size;Date;CheckSumm
c:\Windows\Temp\;atest3.dll;Size;Date;CheckSumm
c:\Windows\Temp\;stest4.dll;Size;Date;CheckSumm
c:\Windows\System32\;test3.dll;Size;Date;CheckSumm
c:\Windows\System32\;test4.dll;Size;Date;CheckSumm
c:\Windows\System32\;test5.dll;Size;Date;CheckSumm
c:\Windows\System32\;test6.dll;Size;Date;CheckSumm
c:\Windows\System32\;test7.dll;Size;Date;CheckSumm
c:\Windows\System32\;test8.dll;Size;Date;CheckSumm
c:\Windows\System32\;test9.dll;Size;Date;CheckSumm