用OpenFileDialog多选一次选择多个文件,然后把这些文件列在ListBox中,有什么不办法只显示文件的名,而不是文件的全路径!谢谢!

解决方案 »

  1.   


                string str = "c:/123.txt";
                string fileName=str.Substring(str.LastIndexOf('/')+1 ));
      

  2.   

    多选的啊,filename是字符数组啊!有没有方法:虽然只显示了文件的名字,可是文件的实际也能存在!
      

  3.   

    string str="c:\123.txt";
    listBox1.Items.Add(str.Substring(str.LastIndexOf('\\')+1,str.Length-str.LastIndexOf('\\')-1));
      

  4.   

    string strs[] 
    foreach(string str in strs)
    {
    listBox1.Items.Add(str.Substring(str.LastIndexOf('\\')+1,str.Length-str.LastIndexOf('\\')-1));
    }
      

  5.   

    最简单的方法:string fileName = Path.GetFileNameWithoutExtension("C:\\Test\\Demo\\AA.txt");
    // fileName = "AA"
      

  6.   

    可是设置打开文件对话框多选的属性为true啊
      

  7.   

    List<string> lis = new List<string>();
                        foreach (string str in ofdOpen.FileNames)
                        {
                            li.Add(str);
                        }foreach(string li in lis)
    {
    listBox1.Items.Add(str.Substring(li.LastIndexOf('\\')+1,str.Length-str.LastIndexOf('\\')-1));
    }
      

  8.   

    搞一个 list 存 全路径 ,顺序与listbox一样,选哪个项去读哪个相应的路径 倒是能实现你的想法
      

  9.   


                OpenFileDialog openfile = new OpenFileDialog();
                openfile.Multiselect = true;
                openfile.Filter = "信息Excel2003文件(*.xls)|*.xls";
                openfile.Title = "请选择信息";
                if (openfile.ShowDialog() == DialogResult.OK)
                {
                    this.TDpath = Path.GetDirectoryName(openfile.FileName);
                    TDfiles = openfile.SafeFileNames;
                }SafeFileNames这个属性啊 取到的就是完整的文件名 去掉前面的路径的 不管你路径多么复杂都可以要装了.Net2.0或者以上版本才有OpenFileDialog.SafeFileNames这个属性
      

  10.   

    嘿嘿,还是你解决了我的问题啦!虽然不会linq当时也差不多明白了,谢谢了,分给你了