int at;
string[] dirs = Directory.GetFiles(@AppDomain.CurrentDomain.SetupInformation.ApplicationBase+@"Report\");
foreach (string dir in dirs)
{
at=dir.LastIndexOf("\\");
MessageBox.Show(at.ToString());
string str;
str=dir.Substring(at+1,dir.Length-at);
treeView1.Nodes.Add(str);
}
怎么会提示错误,不能把文件名添加到Treeview中
string[] dirs = Directory.GetFiles(@AppDomain.CurrentDomain.SetupInformation.ApplicationBase+@"Report\");
foreach (string dir in dirs)
{
at=dir.LastIndexOf("\\");
MessageBox.Show(at.ToString());
string str;
str=dir.Substring(at+1,dir.Length-at);
treeView1.Nodes.Add(str);
}
怎么会提示错误,不能把文件名添加到Treeview中
解决方案 »
- wcf 多个客户端对应同一个服务 如何实现多个endpoint
- varbinary(max)字段存放的数组如何读取?
- 一个比较白痴的问题
- 怎样用C#获取Form上或控件上某一点的颜色,并且重新设置颜色?急!!在线等!!
- 请问“验证输入是否为数字”是在控件里写。还是在HTML里写呢?
- ASP.NET Forums 2.0 论坛源代码 学习的好机会!!!!!!
- 请教给位一个问题希望大家帮帮忙呀!
- 一个.txt的纯文本文件最多能有多少行?
- 自定义控件的问题
- 想了七个公司名称, 请大家评价一下, 哪一个名称更响亮、好听?? 谢谢!!!
- 高分求教!为何C#写的输出流无法全部写入文件中?
- 如何自己新建一个DataGridView的列类型?
Parameter name:length.
这里的Add()括号里面应该是一个node,而你的是一个string,应该先定义一个node
把str赋值给node.Text
然后treeView1.Nodes.Add(node);
int at;
string[] dirs = Directory.GetFiles(@AppDomain.CurrentDomain.SetupInformation.ApplicationBase+@"Report\");
foreach (string dir in dirs)
{
//treeView1.Nodes.Add(dir);
at=dir.LastIndexOf("\\");
MessageBox.Show(at.ToString());
string str;
str=dir.Substring(at+1,dir.Length-at);
TreeNode tn= new TreeNode();
tn.Text=str;
treeView1.Nodes.Add(tn);
}
未处理的“System.IO.DirectoryNotFoundException”类型的异常出现在 mscorlib.dll 中。其他信息: Could not find a part of the path "D:\test\WindowsApplication1\bin\Debug\Report\".运行时错误我先编译,再去执行exe文件又出现:
An unhandled exception has occurred in your application.If you click Continue,the application whill ignore this error and attempt to continue.If you click Quit,the application will be shut down immediately.Indx and length must refer to a location within the string.
Parameter name:length.
str=dir.Substring(at+1,dir.Length-at-1);
改成 str=dir.Substring(at+1,dir.Length-at-1);