如何在vb.net中找到exe文件的绝对路径

时间:2011-01-13 09:38:28

标签: vb.net filesystems

  

可能重复:
  How can I get the application's path in .NET in a console app?

您好,

我想找到运行exe文件的绝对路径。

即如果我从c:\ my-app \ myapp.exe运行我的应用程序/ exe,那么它应该返回c:\ my-app。

我的目标是在db文件夹中找到我的数据库位置。

1 个答案:

答案 0 :(得分:2)

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase为您提供了exe的名称,然后System.IO.Path.GetDirectoryName(...)将目录部分拉出来。

请参阅http://msdn.microsoft.com/en-us/library/aa457089.aspx#howtoexecutingapppath_topic2