C#中FileUpLoad控件,取FileName

来源:百度知道 编辑:UC知道 时间:2024/05/22 03:10:03
取的时候总是有后缀名怎么去掉后缀名?

string x="sdfght.mp3";//转换前
x=x.Substring(0,x.LastIndexOf('.'));//转换后

string fileName = System.IO.Path.GetFileNameWithoutExtension(@"c:\a.txt");

2楼的方法很好,只可惜不适用在非本地的文件路径上,还是1楼的比较实际点。

System.IO.Path.GetFileNameWithoutExtension(File1.PostedFile.FileName)即可