在App.xaml.cs中获取应用程序运行路径

时间:2009-09-08 06:03:11

标签: wpf

如何从app.xaml.cs本身获取应用程序的运行路径?

3 个答案:

答案 0 :(得分:11)

你可以尝试

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

AppDomain.CurrentDomain.BaseDirectory

和/或

Environment.CurrentDirectory

答案 1 :(得分:1)

您可以使用System.Environment.GetCommandLineArgs属性来获取启动应用程序的命令行。使用System.IO.Path方法解析它,只提取可执行文件的文件名或完整路径。

var exeName = System.IO.Path.GetFileName(
    System.Environment.GetCommandLineArgs()[0]);
MessageBox.Show("This exe's filename is " + exeName);

答案 2 :(得分:0)

这始终有效:

System.Windows.Forms.Application.StartupPath
相关问题