zoukankan      html  css  js  c++  java
  • C# 获取程序路径的主要方法和区别如下

    C# 获取程序路径的主要方法和区别如下:

    ```csharp
    //1.获取模块的完整路径(即程序名+.vshost.exe)是visual studio宿主应用程序,vs运行调试时是打开的其实是这个文件,这个程序可以让vs跟踪调试信息。
    string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebugSD_MyTest.vshost.exe

    //2.获取和设置当前目录(该进程从中启动的目录)的完全限定目录
    string path2 = System.Environment.CurrentDirectory;
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebug

    //3.获取应用程序的当前工作目录
    string path3 = System.IO.Directory.GetCurrentDirectory();
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebug

    //4.获取程序的基目录
    string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebug

    //5.获取和设置包括该应用程序的目录的名称
    string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebug

    //6.获取启动了应用程序的可执行文件的路径
    string path6 = System.Windows.Forms.Application.StartupPath;
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebug

    //7.获取启动了应用程序的可执行文件的路径及文件名
    string path7 = System.Windows.Forms.Application.ExecutablePath;
    //C:UsersAdministratorDocumentsVisual Studio 2015ProjectsSD_MyTestinDebugSD_MyTest.EXE
    ```

  • 相关阅读:
    Django -- 路由系统(URLconf)
    Django简介
    jQuery
    DOM
    JavaScript
    HTML,CSS
    Redis PK Memcached
    ORM框架-SQLAlchemy
    Memcached操作以及用法
    Py3快速下载地址
  • 原文地址:https://www.cnblogs.com/liangyuwen/p/13205374.html
Copyright © 2011-2022 走看看