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
  • 相关阅读:
    线性支持向量机分类
    字符识别--模型集成
    字符识别--模型的训练与验证
    反射案例当中pro.load()报错问题的解决
    字节码对象功能
    BS案例服务器之系统找不到指定路径
    内部类接口实现线程
    多个异常,一次捕获,多次处理
    Objects.requireNonNull
    intellij idea编译java出现kotlin:connecting to daemon
  • 原文地址:https://www.cnblogs.com/enych/p/9441312.html
Copyright © 2011-2022 走看看