如何在Windows窗体应用程序中获取应用程序的物理路径

9
如何在Windows表单中获取应用程序路径,我使用了以下代码但是它显示“找不到方法”。
Application.ExecutablePath;
Application.StartupPath;

请问我是否遗漏了任何命名空间?

提前感谢。

5个回答

15

这将返回您的应用程序的完整路径

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

5
你也可以这样做。
          System.AppDomain.CurrentDomain.BaseDirectory

2

System.Windows.Forms.Application.StartupPath必须返回运行可执行文件的路径。


1

添加引用 System.Windows.Forms 并在 using 部分中添加

using System.Windows.Forms;

0
通常,Application.StartupPath()会给出应用程序的路径。您还少了这个命名空间:System.Windows.Forms

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接