获取程序目录
string s = System.IO.Directory.GetCurrentDirectory(); Console.WriteLine(s);// C:Users -documentsvisual studio 2013ProjectsTestMVCConsoleApplication1inDebug s=s.Substring(0,s.LastIndexOf("\")); Console.WriteLine(s);//C:Users -documentsvisual studio 2013ProjectsTestMVCConsoleApplication1in s=s.Substring(0, s.LastIndexOf("\")); Console.WriteLine(s);//C:Users -documentsvisual studio 2013ProjectsTestMVCConsoleApplication1
其他总结
//获取到bin目录的下层路径:binDebug string aa = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string cc = System.AppDomain.CurrentDomain.BaseDirectory; //获取到bin目录:binDebug string dd = System.Environment.CurrentDirectory; string ee = System.IO.Directory.GetCurrentDirectory(); string ff = System.Windows.Forms.Application.StartupPath; //获取程序.exe string bb = System.Windows.Forms.Application.ExecutablePath;