C# 取得路径

 

C#获取相对路径 - SteveWang - 博客园 (cnblogs.com)

string str1 = System.Environment.CurrentDirectory; //Result: C:xxxxxx
MessageBox.Show(str1, "A message from AlertService.");
string str2 = System.IO.Directory.GetCurrentDirectory(); //Result: C:xxxxxx
MessageBox.Show(str2, "A message from AlertService.");
string str3 = System.IO.Directory.GetCurrentDirectory(); //Result: C:xxxxxx
MessageBox.Show(str3, "A message from AlertService.");
string str4 = System.Windows.Forms.Application.ExecutablePath; //Result: C:xxxxxxxxx.EXE
MessageBox.Show(str4, "A message from AlertService.");
string str5 = System.AppDomain.CurrentDomain.BaseDirectory;  //Result: C:xxxxxx
MessageBox.Show(str5, "A message from AlertService.");
string str6 = System.AppDomain.CurrentDomain.BaseDirectory;  //Result: C:xxxxxx
MessageBox.Show(str6, "A message from AlertService.");
string str7 = this.GetType().Assembly.Location; //Result: C:xxxxxxxxx.exe
MessageBox.Show(str7, "A message from AlertService.");
string str8 = this.GetType().Assembly.Location; //Result: C:xxxxxxxxx.exe
MessageBox.Show(str8, "A message from AlertService.");
string path9 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"moduleM3ExampleMuColor.txt";
MessageBox.Show(path9, "A message from AlertService.");

posted @ 2022-09-27 13:42  淡淡的思绪  阅读(53)  评论(0)    收藏  举报