DirectoryInfo dir = new DirectoryInfo(e.Node.FullPath);
DirectoryInfo[] folds = dir.GetDirectories();
foreach(DirectoryInfo f in folds)
{
TreeNode subnode = new TreeNode();
subnode.Text = f.Name;
e.Node.Nodes.Add(subnode); }
未处理的“System.NotSupportedException”类型的异常出现在 mscorlib.dll 中。其他信息: 不支持给定路径的格式。 我一点驱动器就出这样的错,我拿同样的代码在别人的机器上用就是好的,怎么回事啊,高手们指点啊
DirectoryInfo dir = new DirectoryInfo(e.Node.FullPath);
这一行抛出的,说的就是 DirectoryInfo的参数不对
不光是a盘,我点哪个驱动器 都是同样的问题,完全的代码如下:
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e){ e.Node.Nodes.Clear();
DirectoryInfo dir = new DirectoryInfo(e.Node.FullPath);→抛出异常的行
DirectoryInfo[] folds = dir.GetDirectories();
foreach(DirectoryInfo f in folds)
{
TreeNode subnode = new TreeNode();
subnode.Text = f.Name;
e.Node.Nodes.Add(subnode); }
}
}
debug 一下,看看传入的e.Node.FullPath是否为合法的值
路径没问题的,我的treeview的根节点是 "外部管理目录"
上叙代码是属于 子节点,我messagebox.show出来的值是 "外部管理目录/d:/" 没错啊...
DirectoryInfo dir = new DirectoryInfo(e.Node.FullPath);→抛出异常的行
}
catch(Exception e)
{
if(e is System.NotSupportedException)//用来确定,这个System.NotSupportedException就是它直接抛出的
MessageBox.Show("NotSupportedException");
else
MessageBox.Show(e.Message.ToString);
//在MSDN里,这个new DirectoryInfo(e.Node.FullPath);可能抛出的异常是四种,没有你说的这个System.NotSupportedException异常啊,晕晕地
}