菜鸟求教
请问大家,怎么用XML配置文件遍历我的电脑,在窗体里把里面的文件夹显示出来?
谢谢
解决方案 »
- 关于Excel导入Combox
- 求助 panel 上放置很多控件 拖动滚动条 重影的解决办法
- compact framwork下Object转化为Byte[]
- bindingNavigator控件的问题
- WinForm程序已经存在.resx资源文件,里面已有图片资源,如何在此基础上再添加图片资源?
- 我想在我的.net程序中调用摄象头大体应该怎么做
- 很简单的问题,怎样求得整形数组中的最大值
- WPF 做的窗口在 Vista下不能正确显示
- c#用GetFiles()获得的文件列表,如何排序才能与在本机文件夹上按名称排的完全一致?
- 关于使用RS485通讯的问题
- C#Winform 关闭窗体后,程序还在运行,如何停止程序?
- C# 主程序失去焦点后MessageBox怎么变为非模式了?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
CreateParent();
} void CreateParent()
{
string path="";//这里写路径,读取的文件是这个路径下的所有文件,包括子文件
TreeNode parent = new TreeNode();
parent.Text = path;
tvType.Nodes.Add(parent);
CreateChild(path,parent);
}
void CreateChild(string path, TreeNode parent)
{
DirectoryInfo di = new DirectoryInfo(path);
DirectoryInfo[] arrs = di.GetDirectories();
foreach(DirectoryInfo arr in arrs)
{
TreeNode child = new TreeNode();
child.Text = arr.Name;
child.Tag = arr.FullName;
parent.Nodes.Add(child);
CreateFile(arr.FullName, child);
}
}
void CreateFile(string path, TreeNode child)
{
DirectoryInfo files = new DirectoryInfo(path);
FileInfo[] fis = files.GetFiles();
foreach (FileInfo fi in fis)
{
TreeNode f = new TreeNode();
f.Text = fi.Name;
f.Tag = fi.FullName;
child.Nodes.Add(f);
}
}
}