C# Application.ExecutablePath on WPF Framework 3.5

别说谁变了你拦得住时间么 提交于 2019-12-05 23:44:10
Dzmitry Martavoi

There are several ways to get exe path. Try the next:

  • Application.StartupPath
  • Path.GetDirectoryName(Environment.GetCommandLineArgs()[0])
  • Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
  • Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
  • System.Reflection.Assembly.GetEntryAssembly().Location

Try this:

System.IO.Path.GetDirectoryName( 
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

You can unpack a Uri like this:

string codeBase = Assembly.GetExecutingAssembly().CodeBase;
   UriBuilder uri = new UriBuilder(codeBase);
   string path = Uri.UnescapeDataString(uri.Path);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!