原来我是想截取文件名,前面的路经不要了,但是运行时保错,说startIndex不能小于0;
Remote_add=Request.UserHostAddress;
path =@"\"+Remote_add+"\back\trade_back_"+DateTime.Now.Year+"_"+DateTime.Now.Month+"_"+DateTime.Now.Day+"_"+DateTime.Now.Hour+"_"+DateTime.Now.Minute+"_"+DateTime.Now.Second+".bak";
path2=path.Substring(path.IndexOf("trade"),path.Length-path.IndexOf("trade"));
各位有谁有什么好办法帮我把前面的路经去掉嘛?

解决方案 »

  1.   

    string[] FileSplit = xxxx.Split('\\');

    string fileName=FileSplit[FileSplit.Length-1]; 其中xxxx是你的路径字符串,fileName为得到的文件名..
      

  2.   

    string s = sfile.substring(s.LastIndexOf("\\") + 1);
      

  3.   

    我只要文件名阿就是 XXXX.bak的样子
      

  4.   

    Remote_add = Request.UserHostAddress;
                path2 = "trade_back"+"_";
                path2 += DateTime.Now.Year.ToString()+"_";
                path2 += DateTime.Now.Month.ToString()+"_";
                path2 += DateTime.Now.Day.ToString()+"_";
                path2 += DateTime.Now.Hour.ToString()+"_";
                path2 += DateTime.Now.Minute.ToString()+"_";
                path2 += DateTime.Now.Second.ToString()+"_";
                path2 += ".bak";            path = @"\" + Remote_add + @"\back\"+path2;
      

  5.   

    试一下
    Uri 类或Path类来处理