对话框得到路径后string sPath = OpenFileDialog.FileName,\\如:路径c:\data\abc.txt
如何取得文件名(不包括路径)和文件的路径(不包括文件名)?
我用char[] sep = {'\'};string[] sval = Path.Split(sep);可'\'不能是char,总说字浮太多,请高手指教,立即结贴!

解决方案 »

  1.   

    string[] sval = Path.Split("\\");
      

  2.   

    string fliename = Path.Substring(Path.LastIndexOf("\\")+1);
      

  3.   

    string sPath = OpenFileDialog.FileName;
    int allnum = sPath.Length;
    int pos = sPath.LastIndexOf(@"\");
    appPath = sPath.Substring(0, pos);//文件的路径(不包括文件名)
    appPath = sPath.Substring(pos,allnum);//文件名(不包括路径)
      

  4.   

    string sPath = OpenFileDialog.FileName
    System.IO.Path.GetFileNameWithoutExtension( sPath );