zoukankan      html  css  js  c++  java
  • C#获取当前路径的方法

       //获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。  
                string str1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                System.Diagnostics.Debug.WriteLine (str1);
                //////     E:学习工程C#c#教程TestTestinDebugTest.vshost.exe
     

                //获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。  
                string str2 = System.Environment.CurrentDirectory;
                System.Diagnostics.Debug.WriteLine(str2);
                //////E:学习工程C#c#教程TestTestinDebug
     

                //获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。  
                string str3 = System.AppDomain.CurrentDomain.BaseDirectory;
                System.Diagnostics.Debug.WriteLine(str3);
                //////E:学习工程C#c#教程TestTestinDebug  

                //获取和设置包含该应用程序的目录的名称。  
                string str4 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                System.Diagnostics.Debug.WriteLine(str4);
                //////E:学习工程C#c#教程TestTestinDebug  

                //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。  
                string str5 = System.Windows.Forms.Application.StartupPath;
                System.Diagnostics.Debug.WriteLine(str5);
                //////E:学习工程C#c#教程TestTestinDebug  

                //获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。  
                string str6 = System.Windows.Forms.Application.ExecutablePath;
                System.Diagnostics.Debug.WriteLine(str6);
                //////E:学习工程C#c#教程TestTestinDebugTest.EXE

                //获取应用程序的当前工作目录(不可靠)。  
                string str7 = System.IO.Directory.GetCurrentDirectory();
                System.Diagnostics.Debug.WriteLine(str7);
                //////E:学习工程C#c#教程TestTestinDebug

  • 相关阅读:
    Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!
    showModalDialog和showModelessDialog的使用
    如何在GridView中使用DataFromatString
    GridView/DataGrid单元格不换行的问题
    要Gmail、Orkut邀请的请留下你的邮箱
    How to reset security settings back to the defaults
    ASP.NET 2.0 学习笔记 1: session 与 script 应用
    关闭主窗体而不退出主程序 以及如何获取操作系统的关闭、注销信息
    ASP.NET 2.0 学习笔记 2: 页面间传值
    Windows 系统常用设置方法与技巧
  • 原文地址:https://www.cnblogs.com/dongh/p/15150847.html
Copyright © 2011-2022 走看看