代码如下:
private void GetFileInfo(string filePath, TreeNode node)
{
DirectoryInfo directoryInfo = new DirectoryInfo(filePath);
try
{
foreach (DirectoryInfo childDirectoryInfo in directoryInfo.GetDirectories())
{
TreeNode directoryNode = new TreeNode(childDirectoryInfo.Name.ToString());
directoryNode.Tag = childDirectoryInfo.Name.ToString();
GetFileInfo(filePath + "\\" + childDirectoryInfo.Name.ToString(), directoryNode);
node.Nodes.Add(directoryNode);
}
foreach (FileInfo fileInfo in directoryInfo.GetFiles("*.html"))
{
TreeNode leafNode = new TreeNode();
leafNode.Text = fileInfo.Name.ToString().Substring(0,fileInfo.Name.ToString().IndexOf(".html"));
leafNode.Tag = fileInfo.Name.ToString();
node.Nodes.Add(leafNode);
}
catch
{
}
}
使用介绍:
TreeNode treenode = new TreeNode();
treenode.Text = "报表树";
GetFileInfo(@"C:\AutoReport", treenode);
this.treeView1.Nodes.Add(treenode);
声明:
这段代码,只能够显示html的,如果您要使用,请视情况修改 foreach (FileInfo fileInfo in directoryInfo.GetFiles("*.html"))
这个。。。。
有事Q我:
姓名:颜昌钢
联系方式:yanchanggang@boco.com.cn
电话:13886086508
QQ:95550107
公司:亿阳集团武汉分公司
移动飞信:647360243