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

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

    string str = System.Environment.CurrentDirectory;

    Result: C:xxxxxx

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

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

    Result: C:xxxxxx

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

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

    Result: C:xxxxxxxxx.exe

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

    string str = System.AppDomain.CurrentDomain.BaseDirectory;

    Result: C:xxxxxx

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

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

    Result: C:xxxxxx

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

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

    Result: C:xxxxxx

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

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

    Result: C:xxxxxxxxx.exe

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

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

    Result: C:xxxxxxxxx.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;//获取或设置包含该应用程序的目录的名称。

      转自[http://www.cnblogs.com/bnuvincent/archive/2009/08/12/1544357.html]

  • 相关阅读:
    挂载磁盘不成功显示mount: /mnt: wrong fs type, bad option, bad superblock..............
    Linux如何查看文件的创建、修改时间?
    Linux,Centos下 Tomcat8 修改jvm内存配置的新方法
    ActiveMQ问题分析和解决
    centos如何删除文件夹
    CentOS 几种重启方式的区别
    CentOS查看文件夹大小
    挂在光盘出现写保护mount: block device /dev/sr0 is writeprotected, mounting readonly
    centos7安装activeMq
    Rust中的workspace
  • 原文地址:https://www.cnblogs.com/lucky_hu/p/3548697.html
Copyright © 2011-2022 走看看