string filePath = System.Web.HttpContext.Current.Request.MapPath("~/Upload"); //由虚拟路径指定的服务器上的物理路径 string filePath1 = System.Web.HttpContext.Current.Server.MapPath("~/Upload"); //对应于路径的Web服务器上的物理文件路径。 string filePath2 = System.Web.Hosting.HostingEnvironment.MapPath("~/Upload"); //由虚拟路径指定的服务器上的物理路径
string filePath = System.Web.HttpContext.Current.Request.MapPath("");//获得控制器名字目录下的
filePath = System.Web.HttpContext.Current.Request.MapPath("../");//获得控制器的上级目录
winform
var s1 = System.IO.Directory.GetCurrentDirectory(); //D:\abc\bin\Debug
string s2 = System.Windows.Forms.Application.StartupPath; //D:\abc\bin\Debug
string s3 = System.AppDomain.CurrentDomain.BaseDirectory; //D:\abc\Debug\
System.IO.DirectoryInfo topDir = System.IO.Directory.GetParent(System.Environment.CurrentDirectory);
//继续获取上级的上级的上级的目录。
string pathto = topDir.Parent.Parent.FullName;