zoukankan      html  css  js  c++  java
  • c# 相对路径的一些文献

    1.获取和设置当前目录的完全限定路径。

    string str = System.Environment.CurrentDirectory;

    Result: C:\xxx\xxx

    2.获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。

    string str = System. Windows .Forms.Application.StartupPath;

    Result: C:\xxx\xxx

    3.获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名。

    string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

    Result: C:\xxx\xxx\xxx.exe

    4.获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。

    string str = System.AppDomain.CurrentDomain.BaseDirectory;

    Result: C:\xxx\xxx\

    5.获取应用程序的当前工作目录。

    string str = System.IO.Directory.GetCurrentDirectory();

    Result: C:\xxx\xxx

    6.获取和设置包含该应用程序的目录的名称。

    string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

    Result: C:\xxx\xxx\

    7.获取当前进程的完整路径,包含文件名。

    string str = this.GetType().Assembly.Location;

    Result: C:\xxx\xxx\xxx.exe

    8.获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。

    string str = System. Windows .Forms.Application.ExecutablePath;

    Result: C:\xxx\xxx\xxx.exe

    此外,更多见的通过XML文件配置具体的路径来达到合理的规划配置文件的具体存放位置,如WEB中的配置文件中的路径。




     string   str1   =Process.GetCurrentProcess().MainModule.FileName;//可获得当前执行的exe的文件名。      
      string   str2=Environment.CurrentDirectory;//获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。  
      //备注   按照定义,如果该进程在本地或网络驱动器的根目录中启动,则此属性的值为驱动器名称后跟一个尾部反斜杠(如“C:\”)。如果该进程在子目录中启动,则此属性的值为不带尾部反斜杠的驱动器和子目录路径(如“C:\mySubDirectory”)。  
      string   str3=Directory.GetCurrentDirectory();//获取应用程序的当前工作目录。  
      string   str4=AppDomain.CurrentDomain.BaseDirectory;//获取基目录,它由程序集冲突解决程序用来探测程序集。  
      string   str5=Application.StartupPath;//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。  
      string   str6=Application.ExecutablePath;//获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。  
      string   str7=AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//获取或设置包含该应用程序的目录的名称。
  • 相关阅读:
    winform把所有dll打包成一个exe
    Windows10+Python3下安装NumPy+SciPy+Matplotlib
    Windows10+Python3+BeautifulSoup4 安装
    解决:无法在发送 HTTP 标头之后进行重定向。 跟踪信息: 在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>……
    "请求被中止: 未能创建 SSL/TLS 安全通道"解决办法
    被“1”和“l”给坑了
    谁把我的代码覆盖了
    jQueryUI datepicker 报错: TypeError: inst is undefined
    VS 附加不上w3wp.exe
    MySQL性能调优与架构设计——第 18 章 高可用设计之 MySQL 监控
  • 原文地址:https://www.cnblogs.com/bnuvincent/p/1544357.html
Copyright © 2011-2022 走看看