【转】C#获取当前路径7种方法

时间:2021-07-18 15:29:19
webform
var s = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; //C盘 IIS路径
var s1 = System.Environment.CurrentDirectory; //同上
var s2 = System.IO.Directory.GetCurrentDirectory();//同上
var s3 = System.AppDomain.CurrentDomain.BaseDirectory; //当前项目根目录
var s4 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; //同上

  

winform

System.Windows.Forms.Application.StartupPath
System.Windows.Forms.Application.ExecutablePath