C# 获得根路径


asp.net:

System.Web.HttpContext.Current.Server.MapPath("~/App_Data/tmp/");

winform:

System.AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\tmp\\";

AppDomain.CurrentDomain.RelativeSearchPath

if (HttpContext.Current == null)
{
    serverLogPath = AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\tmp\\";
}
else
{
    serverLogPath = HttpContext.Current.Server.MapPath("~/App_Data/tmp/");
}
GarsonZhang www.yesdotnet.com

获取当前运行程序

windows app的执行路径AppDomain.CurrentDomain.BaseDirectory

asp.net的执行路径AppDomain.CurrentDomain.SetupInformation.PrivateBinPath或者AppDomain.CurrentDomain.RelativeSearchPath

后者获取回来是带有“bin”文件夹在后面的

 

ASP.NET MVC测试

C# 全选
System.Environment.CurrentDirectory // E:\\GZ\\GZBlog\\YESCMS
System.AppDomain.CurrentDomain.BaseDirectory // E:\GZ\GZBlog\YESCMS\bin\Debug\net5.0\
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase // E:\GZ\GZBlog\YESCMS\bin\Debug\net5.0\
AppDomain.CurrentDomain.RelativeSearchPath // null

C# 获得根路径

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
YES开发框架
上一篇:C#错误异常日志记录到文件
下一篇:SQLite Database 多线程访问需要注意的问题
评论列表

发表评论

评论内容
昵称:

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码