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
    ```
  • 相关阅读:
    error: declaration of 'cv::Mat R ' shadows a parameter
    Java网络编程(二)
    排序算法(二)
    Java网络编程(一)
    排序算法(一)
    Python文件访问模式
    Python文件与异常
    递归
    SQL命令的六个主要类别
    iOS-生成Bundle包-引入bundle-使用bundle
  • 原文地址:https://www.cnblogs.com/zhengxia/p/11752722.html
Copyright © 2011-2022 走看看