region 獲取文件名稱 02 /// <summary> 03 /// 獲取文件名稱 04 /// </summary> 05 /// <param name="path">路徑</param> 06 /// <returns></returns> 07 public static string GetFileName(String path) 08 { 09 if (path.Contains("\\")) 10 { 11 string[] arr = path.Split('\\'); 12 return arr[arr.Length - 1]; 13 } 14 else 15 { 16 string[] arr = path.Split('/'); 17 return arr[arr.Length - 1]; 18 } 19 } 20 #endregion 21 #region 獲取文件后綴名 22 /// <summary> 23 /// 獲取文件后綴名 24 /// </summary> 25 /// <param name="filename">文件名</param> 26 /// <returns></returns> 27 public static String GetFex(string filename) 28 { 29 return filename.Substring(filename.LastIndexOf(".") + 1); 30 } 31 #endregion 32 #region 獲取文件目錄 33 /// <summary> 34 /// 獲取文件后綴名 35 /// </summary> 36 /// <param name="filename">文件名</param> 37 /// <returns></returns> 38 public static String GetDirectory(string filename) 39 { 40 return filename.Substring(0, filename.LastIndexOf("/")); 41 } 42 #endregion 43 #region 返回當(dāng)前虛擬目錄的真實(shí)目錄 44 /// <summary> 45 /// 返回當(dāng)前虛擬目錄的真實(shí)目錄 46 /// </summary> 47 /// <param name="SavePath">虛擬目錄</param> 48 /// <param name="iscreate">沒有是否創(chuàng)建</param> 49 /// <returns></returns> 50 internal static string GetPath(string SavePath, bool iscreate) 51 { 52 string path = System.Web.HttpContext.Current.Server.MapPath(SavePath); 53 if (!System.IO.Directory.Exists(path) && iscreate) 54 { 55 System.IO.Directory.CreateDirectory(path); 56 } 57 return path; 58 } 59 #endregion 60 #region 返回當(dāng)前虛擬路徑的真實(shí)路徑 61 /// <summary> 62 /// 返回當(dāng)前虛擬路徑的真實(shí)路徑 63 /// </summary> 64 /// <param name="SavePath">虛擬路徑</param> 65 /// <param name="iscreate">沒有是否創(chuàng)建</param> 66 /// <returns></returns> 67 public static string GetFilePath(string SavePath, bool iscreate) 68 { 69 return GetPath(VirtualPathUtility.GetDirectory(SavePath), iscreate); 70 } 71 #endregion |
|