C#中获取当前路径的几种方法

来源:互联网 发布:淘宝服饰女装 编辑:程序博客网 时间:2024/05/26 12:08

要在c#中获取路径有好多方法,一般常用的有以下五种:


        //获取应用程序的当前工作目录。
        String path1 = System.IO.Directory.GetCurrentDirectory();


        //获取程序的基目录。
        String path2 = System.AppDomain.CurrentDomain.BaseDirectory;


        //获取和设置包括该应用程序的目录的名称。
        String path3 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;


        //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
        String path4 = System.Windows.Forms.Application.StartupPath;


        //获取启动了应用程序的可执行文件的路径及文件名
        String path5 = System.Windows.Forms.Application.ExecutablePath;