多个获取WinForm程序所在文件夹路径的方法,收藏备忘。
代码:string str =this.GetType().Assembly.Location;
结果:result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
代码:string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
结果:result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
代码:string?str?=?System.Environment.CurrentDirectory;
结果:result: X:\xxx\xxx (.exe文件所在的目录)
代码:string?str?=?System.AppDomain.CurrentDomain.BaseDirectory;
结果:result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
代码:string?str?=?System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
结果:result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
代码:string?str?=?System.Windows.Forms.Application.StartupPath;
结果:result: X:\xxx\xxx (.exe文件所在的目录)
代码:string?str?=?System.Windows.Forms.Application.ExecutablePath;
结果:result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
代码:string?str?=?System.IO.Directory.GetCurrentDirectory();
结果:result: X:\xxx\xxx (.exe文件所在的目录)
原文:http://www.cnblogs.com/huhangfei/p/5019634.html