app_code文件夹下使用MapPath - 摘自discuz!nt 2.5 /// <summary> /// 获得当前绝对路径 /// </summary> /// <param name="strPath">指定的路径</param> /// <returns>绝对路径</returns> public static string GetMapPath(string strPath) { if (HttpContext.Current != null) { return HttpContext.Current.Server.MapPath(strPath); } else //非web程序引用 { strPath = strPath.Replace("/", "//"); if (strPath.StartsWith("//")) { strPath = strPath.Substring(strPath.IndexOf('//', 1)).TrimStart('//'); } return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath); } }