首页 > Windows开发 > 详细

C#读取路径

时间:2018-01-06 13:36:08      阅读:304      评论:0      收藏:0      [点我收藏+]

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

 

C#读取路径

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!