zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    微信小程序上拉分页
    关于检测数据类型,三种方法(typeof,instanceof,Object.prototype.toString.call())优缺点
    如何在Devc++中配置OpenCv
    数据库系统和应用
    这是一篇测试文档
    Pandas 表格合并
    es6一些好用的方法总结
    前端面试题
    超有趣! JS是怎么计算1+2!!!
    彻底理解闭包
  • 原文地址:https://www.cnblogs.com/enych/p/9441312.html
Copyright © 2011-2022 走看看