• C# MVC 获得程序运行路径 .net core


                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:abcinDebug
    string s2 = System.Windows.Forms.Application.StartupPath; //D:abcinDebug
    string s3 = System.AppDomain.CurrentDomain.BaseDirectory; //D:abcDebug

    System.IO.DirectoryInfo topDir = System.IO.Directory.GetParent(System.Environment.CurrentDirectory);
    //继续获取上级的上级的上级的目录。
    string pathto = topDir.Parent.Parent.FullName;

                     dynamic type = (new Program()).GetType();
                        string currentDirectory = System.IO.Path.GetDirectoryName(type.Assembly.Location); //inDebug
    etcoreapp2.2   结尾不带斜杠
                        
                        String basePath1 = AppContext.BaseDirectory; //inDebug
    etcoreapp2.2
                        // //获得程序的运行路径
                        string  path = AppDomain.CurrentDomain.BaseDirectory; // inDebug
    etcoreapp2.2
  • 相关阅读:
    git常用操作命令
    如何编写高质量代码
    Chrome调试工具简单介绍
    使用eclipse+tomcat搭建本地环境
    chrome设置--disable-web-security解决跨域
    利用Maven管理工程项目本地启动报错及解决方案
    用户输入验证【提升篇】
    简单【用户输入验证】
    【消息框】的返回值
    【消息框】的4种显示形式
  • 原文地址:https://www.cnblogs.com/enych/p/9441312.html
Copyright © 2020-2023  润新知