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
    ```

  • 相关阅读:
    linux基础学习6
    Linux基础学习5
    Linux基础学习4
    Linux基础学习3
    Linux基础学习2
    ASP.NET MVC学习——控制器传递数据到view的简单案例
    转载:URL链接中的不同用处
    MVC学习的心路历程
    45道SQL数据题详细超基础解析
    结束基础,开始MVC之旅!
  • 原文地址:https://www.cnblogs.com/liangyuwen/p/13205374.html
Copyright © 2011-2022 走看看