If one day forever

导航

c#中获取路径方法

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

 

            //获取应用程序的当前工作目录。

            String path1 = System.IO.Directory.GetCurrentDirectory();            

            MessageBox.Show("获取应用程序的当前工作目录:" + path1);

  

 

            //获取程序的基目录。

            String path2 = System.AppDomain.CurrentDomain.BaseDirectory;        

            MessageBox.Show("获取程序的基目录:" + path2);

 

  

            //获取和设置包括该应用程序的目录的名称。

            String path3 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;            

            MessageBox.Show("获取和设置包括该应用程序的目录的名称:" + path3);

 

  

            //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。

            String path4 = System.Windows.Forms.Application.StartupPath;           

            MessageBox.Show("获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称:" + path4);

  

 

            //获取启动了应用程序的可执行文件的路径及文件名

            String path5 = System.Windows.Forms.Application.ExecutablePath;           

            MessageBox.Show("获取启动了应用程序的可执行文件的路径及文件名:" + path5);

 

posted on 2010-03-25 16:46  谁啊器是  阅读(235)  评论(0编辑  收藏  举报