部分.net 目录

  1. // 获取程序的基目录。   
  2. System.AppDomain.CurrentDomain.BaseDirectory  
  3.    
  4. // 获取模块的完整路径。   
  5. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName  
  6.    
  7. // 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。   
  8. System.Environment.CurrentDirectory  
  9.    
  10. // 获取应用程序的当前工作目录。   
  11. System.IO.Directory.GetCurrentDirectory()   
  12.   
  13. // 获取和设置包括该应用程序的目录的名称。   
  14. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase  
  15.    
  16. // 获取启动了应用程序的可执行文件的路径。   
  17. System.Windows.Forms.Application.StartupPath   
  18.   
  19. // 获取启动了应用程序的可执行文件的路径及文件名   
  20. System.Windows.Forms.Application.ExecutablePath  
  21.    
  22.    
  23.    
  24. C# WinForm中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别示例如下:  
  25.    
  26. private void Frm_Server_Load(object sender, EventArgs e)  
  27.         {  
  28.             MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);  
  29.             MessageBox.Show(Application.StartupPath );  
  30.          }  
  31.    
  32. 说明:  
  33.    
  34. 1.   AppDomain.CurrentDomain.BaseDirectory 返回结果为: D:\mycode\  
  35.    
  36.      Application.StartupPath 返回结果为: D:\mycode  
  37.    
  38. 2.  Application.StartupPath 只能用于WinForm窗体中,而AppDomain.CurrentDomain.BaseDirectory既可以用于WinForm窗体中,也可以用于类库DLL文件中.  
posted @ 2013-06-03 17:15  zhao69222  阅读(160)  评论(0编辑  收藏  举报