C#读取路径

又一次居然把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("~");

 

posted @ 2018-01-06 11:19  之广  阅读(169)  评论(0编辑  收藏  举报
我的博客——易之广