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中

解决方案 »

  1.   

    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.
      

  2.   

    treeView1.Nodes.Add(str);
    这里的Add()括号里面应该是一个node,而你的是一个string,应该先定义一个node
    把str赋值给node.Text  
    然后treeView1.Nodes.Add(node);
      

  3.   

    我刚刚加了,还是不行
    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);
    }
      

  4.   

    在调试的时候他还有一个错误信息:
    未处理的“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.
      

  5.   

    这一句:
    str=dir.Substring(at+1,dir.Length-at-1);
      

  6.   

    把  str=dir.Substring(at+1,dir.Length-at);
    改成  str=dir.Substring(at+1,dir.Length-at-1);