当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 介绍几个ASP.NET中容易忽略但却很重要的方法函数
给大家介绍几个.NET中Path类的几个方法:
1. Path.combine(string, string)
根据给出的两个路径, 返回一个路径.
例如:
string CompletePath = System.IO.Path.Combine(@"c:\MyApp", @"/upload/tech/20091011/20091011143312_f2fc990265c712c49d51a18a32b39f0c.jpg");
将会返回一个全路径 c:\MyApp\/upload/tech/20091011/20091011143312_f2fc990265c712c49d51a18a32b39f0c.jpg
第一个参数中有无"\"结尾都可以.
2. Path.GetExtension(string)
返回给定文件路径的扩展名.例如:
string FileExtention = System.IO.Path.GetExtention(@"C:\MyApp\/upload/tech/20091011/20091011143312_f2fc990265c712c49d51a18a32b39f0c.jpg");
将会返回 "jpg"
3. Path.GetFileName(string)
给出文件名的全路径,返回文件名(包括扩展名).例如:
string fileName = System.IO.Path.GetFileName(@"c:\MyApp\/upload/tech/20091011/20091011143312_f2fc990265c712c49d51a18a32b39f0c.jpg");
将会返回"/upload/tech/20091011/20091011143314_5ef698cd9fe650923ea331c15af3b160.jpg"
评论 (0) All