就是虚拟目录所在的位置 string path3 = Server.MapPath( " ~ " ); 标签: 原文地址

时间:2022-03-27 06:37:57

又一次居然把C#类中读取文件夹路径跟WebForm(asp.net)中的混淆了,特此整理记录一下。

C#类中一般有一下几种

//根目录下的directory文件夹 string path = AppDomain.CurrentDomain.BaseDirectory + "../../directory"; //项目bin下的Debug string path2 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//AppDomain.CurrentDomain.BaseDirectory //项目bin下的Debug(不怎么使用) string path3 = System.Environment.CurrentDirectory;

WebForm下的Server.MapPath

//获得应用措施根目录地址的位置 string path1 = Server.MapPath("/"); // 获得地址页面确当前目录,,等价于 Server.MapPath("") string path2 = Server.MapPath("./"); //获恰当前应用级措施的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录地址的位置 string path3 = Server.MapPath("~");

标签:

原文地点:https://www.cnblogs.com/shiyige-216/p/8213691.html