-
利用字符串分割法
int lastIndex = filepath.LastIndexOf("\\"); // \\的意思是,一个是转义,一个是代表斜杠
string pFilePath = filepath.Substring(0, lastIndex); //文件路径
string pFileName = filepath.Substring(lastIndex + 1); //文件名
-
利用System.IO.Path提供的方法
string pPath = System.IO.Path.GetDirectoryName(pFullpath); //获取文件路径
string pName = System.IO.Path.GetFileName(pFullpath); //获取文件名
其中,第二种方法更加思路更加简单,较为常用。