C#截取路径中的文件名
string fullPath="f:studyimages(002.jpg ";
int index=fullPath.LastIndexOf("");
string fileName=fullPath.SubString(index+1);//文件名
string fileExtensition=System.IO.Path.GetExtension(fullPath);//扩展名

using System;
using System.IO;
class Test
...{
string path = "d:asdfasdf.bmp";
string fileName = Path.GetFileName(path); //文件名
string ext = Path.GetExtension(path); //扩展名
...
}
string imgname = FileUpload1.PostedFile.FileName;
string imgType = imgname.Substring(imgname.LastIndexOf(".") + 1);
string quanname =DateTime.Now.ToString("yyyyMMddHHmmss")+imgname.LastIndexOf("\")+"."+imgType ;
if ("gif" != imgType && "jpg" != imgType && "GIF" != imgType && "JPG" != imgType)
...{
Response.Write("<script>alert('请选择gif,jpg格式的文件!');</script>");
return;
}
string test="C:\Documents and Settings\Lenovo User\桌面\code.txt";
int i;
String FileName;
i=test.LastIndexOf("\");
FileName=test.Substring(i + 1); 